【转】【WPF】WPF 登录窗口关闭时打开主窗口
在WPF中设计登录窗口关闭时打开主窗口,自动生成的App.xaml不能满足要求,
1、把App.xaml的属性窗口中的生成操作设定为 无
2、添加Program类
static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { LoginWindow loginForm = new LoginWindow(); loginForm.Init(); bool? rt = loginForm.ShowDialog(); loginForm.Close(); if (rt == true) { Application App = new Application(); App.ShutdownMode = ShutdownMode.OnMainWindowClose; MainWindow m_MianWindow = new MainWindow(); App.MainWindow = m_MianWindow; App.Run(m_MianWindow); } } }
方法二:
public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; LoginWindow window = new LoginWindow(); bool? dialogResult = window.ShowDialog(); if ((dialogResult.HasValue == true) && (dialogResult.Value == true)) { base.OnStartup(e); Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; } else { this.Shutdown(); } } }
原文地址:http://www.cnblogs.com/sshoub/archive/2012/08/16/2642262.html