Change Startup Window

后端 未结 3 1757
抹茶落季
抹茶落季 2021-01-01 10:59

I am using Visual Studio 2012 C#. I have created a WPF application project with a main window and added a login window to my project. I want to change the startup window to

3条回答
  •  遥遥无期
    2021-01-01 11:12

    To change the startup window programmatically go to App.xaml remove the line StartupUri="MainWindow.xaml" (This will remove the default startup window configuration), now add the startup event Startup="Application_Startup", in App.xaml.cs

    private void Application_Startup(object sender, StartupEventArgs e)
    {
      If(somecase)
       {
         MainWindow mainWindow = new MainWindow ();
         mainWindow.Show();
       }
      else
       {
         OtherWindow otherWindow= new OtherWindow();
         otherWindow.Show();
       }
    }
    

提交回复
热议问题