In my case I have a main window and a login view.
When the main window is closed, the login window should be displayed. I close it like so:
void CloseOnCompleteAndDisplayLogin(object sender, RunWorkerCompletedEventArgs e)
{
this.Close();
new Login().Show();
}
In the login window I open the MainWindow like so:
this.Hide();
var window = new MainWindow(model).Show();
Problem: When I login and open the MainWindow the first time it works fine. When I close the MainWindow and login again, several functions of the main window stop working or start throwing exceptions.
What am I doing wrong here? I already figured that Window_Loaded like events are not triggered on the re-login.
Yes,
Loadedis not triggered if you Hide/Show. Instead use theShownevent to initialize your logic.