方法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);
}