Prism App Does Not Exit When Closed

匆匆过客 提交于 2020-01-03 15:35:18

问题


I am learning prism and I have hit a problem.

I have made an app very similar to the one that Mike Taulty makes in is great tutoral about Prism. The biggest difference is that my app is a WPF app instead of Silverlight.

I am finding that I have hit a problem though. When I close the main shell window, the app does not exit. The window goes a way, but the debugger is still active.

I have tried looking for call stacks and such, but Visual Studio just tells me that it is "External Code".

Any ideas on what I can do/look for to fix this?


回答1:


Override the OnStartup method in the code behind of your App.xaml, and add this:

this.ShutdownMode = ShutdownMode.OnMainWindowClose; 

HTH




回答2:


The answer of Dyer solve only part of the problem.

I had the same issue, and after a while I found out that region navigation commands are not working well either.

The problem was with the Shell creating in Bootstrapper. When I fixed that, I got 2 Shell windows instances. Why?

The real problem was the startup Uri in the app.xaml. You can't have both startup Uri with Shell creation in Bootstrapper.

Remove it from the app.xaml, fix your Shell and no need is this "Patch" and your app will behave as it should, it will close when you close the Shell.

Again, this is only a symptom, other issues will rise if you don't fix the Shell creation.

protected override DependencyObject CreateShell()
{
    return this.Container.Resolve<Shell>();
}

protected override void InitializeShell()
{
    base.InitializeShell();

    Application.Current.MainWindow = (Shell)this.Shell;
    Application.Current.MainWindow.Show();

    IRegionManager regionManager = this.Container.Resolve<IRegionManager>();
    regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(MainView));
}


来源:https://stackoverflow.com/questions/4114956/prism-app-does-not-exit-when-closed

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