Change Startup Window

后端 未结 3 1710
抹茶落季
抹茶落季 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:09

    use Application.Current.Run Instead of Application.Run

    0 讨论(0)
  • 2021-01-01 11:11

    To change startup window update App.xaml by changing Application.StartupUri:

    <Application ... StartupUri="MainWindow.xaml">
    
    0 讨论(0)
  • 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();
       }
    }
    
    0 讨论(0)
提交回复
热议问题