Reputation: 500
I'm working on a WPF UI and for now I have a login window and a MainWindow with multiple userControls inside the MainWindow, now when the app starts it opens the login window, how can I move to the MainWindow and close the login window when I click on the login button??
Upvotes: 2
Views: 721
Reputation: 7440
Simply close the login window and open the main window.
eg. on a Button Click
private void LoginButton_Click(object sender, EventArgs args)
{
this.Close();
(new MainWindow()).Open();
}
The only thing to keep in mind is the specified ShutdownMode
the default is OnLastWindowClose
If you want to stick with the default ShutdownMode
you could do the following
private void LoginButton_Click(object sender, EventArgs args)
{
this.Hide(); //first hide the LoginWindow
(new MainWindow()).Open();
this.Close(); //now close the LoginWindow, and the "MainWindow" will be the LastWindow
}
Upvotes: 1