How to customize startup of WPF application?

旧城冷巷雨未停 提交于 2019-11-28 22:51:27

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.

Try to use the Startup event (class Application) - MSDN.

You can show MainWindow in this event handler - after you create a Dispatcher instance.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!