WPF App.xaml中ShutdownMode的属性值

OnLastWindowClose(默认值) 最后一个窗体关闭或调用Application对象的Shutdown()方法时,应用程序关闭。
OnMainWindowClose      启动窗体关闭或调用Application对象的Shutdown()方法时,引用程序关闭。(和C#的Windows应用程序的关闭模式比较类似,可应用为主窗体关闭时,应用程序关闭)
OnExplicitShutDown 只有在调用Application对象的Shutdown()方法时,应用程序才会关闭。

 

如何设置关闭选项

1.方法一  

  在项目的App.xaml文件中s设置

 1 <Application x:Class="StudentManagerWPF.App"
 2              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4              xmlns:local="clr-namespace:StudentManagerWPF"
 5              Startup="Application_Startup" ShutdownMode="OnMainWindowClose"
 6              >
 7     <Application.Resources>
 8          
 9     </Application.Resources>
10 </Application>

2.方法二

  在C#后台代码设置,在App.xaml.cs文件中修改,但是注意此设置必须写在app.Run()方法之前

1 app.ShutdownMode = ShutdownMode.OnExplicitShutdown;