繁体   English   中英

关闭我的MainWindow并重新打开它Wpf C#

[英]Close my MainWindow And reopen It Wpf C#

我想关闭并重新打开我的MainWindow。

我有MainWindow,并在导航中放入了一些Page。

现在,我尝试放置一个Disconnect按钮,并希望它关闭MainWindow并重新打开它,因为我希望程序关闭所有BackgroundWorker以及应用程序正在运行的所有东西。

我尝试了类似的东西:

private void Disconnect_Click(object sender, RoutedEventArgs e)
{
    var test = sender as Window;
    MainWindow test2 = new MainWindow();
    test2.Visibility = Visibility.Visible;
    test.Close();
}

但是不行。

还是可以通过Page之间的导航来关闭所有内容?

我找到一个解决方案:

try
{
   // Run the program again
   Process.Start(Application.ResourceAssembly.Location);

   // Close the Old one
   Process.GetCurrentProcess().Kill();
}
catch
{ }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM