关于WPF下用户登录后再启动主窗体的实现方法
/// <summary>App.xaml 的交互逻辑</summary> public partial class App : Application { private bool bFirst = true; private User user; protected override void OnStartup(StartupEventArgs e) { if (bFirst) { Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; WndLogin window = new WndLogin(); bool? dialogResult = window.ShowDialog(); if ((dialogResult.HasValue) && (dialogResult.Value)) { user = window.CurrentUser; bFirst = false; OnStartup(e); Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose; } else { Shutdown(); } } else { MainWindow window = new MainWindow(); window.curUser = user; window.ShowDialog(); } } }
登陆窗体关闭前设置dialogresult为true
经实际测试可行,其余网上大神虽然也是重写OnStartup启动函数,但是经过我的测试,并不能通过,可能我哪里出问题没搞清楚,所以在此记录