2015-07-21 81 views
0

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

我有我的主窗口,我把一些页面导航。

现在,我尝试把一个按钮断开,我想它关闭主窗口,并重新打开它,因为我想要的程序关闭所有的BackgroundWorker和万物的应用程序运行。

我想是这样的:

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

但不起作用。

或者也许我可以作出这样的页面之间关闭所有与导航的东西吗?

回答

0

我找到一个解决方案:

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

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