WPF showing dialog before main window

后端 未结 6 657
无人共我
无人共我 2020-12-03 02:49

How one can show dialog window (e.g. login / options etc.) before the main window?

Here is what I tried (it apparently has once worked, but not anymore):

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 03:02

    here, do it like this. this will actaully change your main window and will work properly w/o having to change settings of your application object.

    make sure to remove the event handler for application startup and to set your StartupUri in your app.xaml file.

    public partial class App : Application
    {
       bool init = false;
       protected override void OnActivated(EventArgs e)
       {
          base.OnActivated(e);
          if (!init)
          {
             this.MainWindow.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
             init = true;
          }
       }
    
       void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
       {
          Window toClose = this.MainWindow;
          this.MainWindow = new Window2();
          this.MainWindow.Show();
       }
    }
    

提交回复
热议问题