最近需要给软件加上登陆界面,所以需要修改WPF的APP

首先,在APP.xaml.cs中写界面的启动程序:

 public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
            
             if (******)
             {
                 base.OnStartup(e);
                 Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
                 MainWindow window = new MainWindow();
                 window.Show();
             }
             else
             {
                 if (System.Windows.MessageBox.Show("Can't open the software! ", "Warning", System.Windows.MessageBoxButton.OK) == System.Windows.MessageBoxResult.OK)
                 {
                     this.Shutdown();
                 }
             }
        }
        //static App()
        //{
        //    DispatcherHelper.Initialize();
        //}
    }

然后在App.xaml中修改StartupUri,一定不能为MainWindow.xaml,否则就算启动条件不正确,程序还在运行MainWindow。

<Application    x:Class="***.App"> 这个一定要加,否则App.xaml.cs根本不运行。

</Application>

posted on 2014-12-11 21:16  樂兒  阅读(1518)  评论(0编辑  收藏  举报