[英]How to move from one window to another in WPF?
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?? 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我点击登录按钮??
Simply close the login window and open the main window.只需关闭登录 window 并打开主 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
唯一要记住的是指定的
ShutdownMode
默认是OnLastWindowClose
https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.shutdownmode?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.shutdownmode?view=netframework-4.8
If you want to stick with the default ShutdownMode
you could do the following如果您想坚持使用默认的
ShutdownMode
,您可以执行以下操作
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.