WPF程序启动和退出

方法1:

(1)app.xaml    StartupUri=“LoginWindow.xaml"

(2)app.xaml.cs    app.StartupUri = new Uri("LoginWindow.xaml", UriKind.Relative); app.Run();

方法2:

app.xaml去掉StartupUri,加ShutdownMode="OnExplicitShutdown"

app.xaml.cs

protected override void OnStartup(StartupEventArgs e)

{
  base.OnStartup(e);

            
  LoginWindow loginWin = new LoginWindow();
            
  loginWin.ShowDialog();
            
  if (loginWin.IsValidate)
  {
                
    MainWindow main = new MainWindow();
                
    main.ShowDialog();
  }
  else

  {
                
    Application.Current.Shutdown(-1);
            
  }

        
}

MainWindow.xaml.cs

 protected override void OnClosed(EventArgs e)
        {
            System.Windows.Application.Current.Shutdown();
            base.OnClosed(e);
        }

猜你喜欢

转载自blog.csdn.net/orc000/article/details/84024705