How to customize startup of WPF application?

You can remove the StartupUri attribute from the App.xaml.

Then, by creating an override for OnStartup() in the App.xaml.cs, you can create your new instance of your Dispatcher class.

Here’s what my quick app.xaml.cs implementation looks like:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
      base.OnStartup(e);

      new MyClassIWantToInstantiate();
    }
  }
}

Update

I recently discovered this workaround for a bug if you use this method to customize app startup and suddenly none of the Application-level resources can be found.

Leave a Comment