title: How to change StartupUri of WPF Application?
body: <p>I am trying to modify App.cs and load the WPF XAML files from code behind but its not working as it should.</p>
  
  <p>No matter whatever I try to set as StartupUri it doesnt start, the program quits after this.</p>
  
  <pre><code>public partial class App : Application
  {
      protected override void OnStartup(StartupEventArgs e)
      {
          base.OnStartup(e);
  
          LoginDialog dlg = new LoginDialog();
          if (dlg.ShowDialog() != true)
              return;
  
          switch (dlg.ChoiceApp) { 
              case ChoiceApp.CustomerEntry:
                  StartupUri = new Uri("/MyApp;component/Forms/CustomerEntry.xaml", 
                      UriKind.Relative);
                  break;
              case ChoiceApp.VendorEntry:
                  StartupUri = new Uri("/MyApp;component/Forms/VendorEntry.xaml", 
                      UriKind.Relative);
                  break;
          }
      }
  }
  </code></pre>
  
  <p>Now I even did trace and found out that LoginDialog is working correctly and is returning values correctly but setting "StartupUri" does not work.</p>
  
  <p>I checked in reverse assembly that DoStartup method of App gets called after OnStartup, so technically my StartupUri must load, but it doesnt, in App.xaml startup uri is not at all defined.</p>
  
  <p><strong>Note: Bug Confirmed</strong></p>
  
  <p>I noticed that ShowDialog sets Application.MainWindow and when dialog ends, it sets it back to null, and because of this setting StartupUri does not work after calling Modal Dialog in OnStartup or Startup event.</p>
  
  <p>There is no error or exception about invalid uri or anything like that.</p>
  
  <p>This method works without DialogBox being called in Startup event or OnStartup, i think calling showdialog on this method causes something like its mainwindow being set to expired window and it shuts down after this.</p>