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;
                this.Shutdown();

原文地址:http://www.cnblogs.com/sshoub/archive/2012/08/16/2642262.html