WPF App.xaml中ShutdownMode的属性值
OnLastWindowClose(默认值) | 最后一个窗体关闭或调用Application对象的Shutdown()方法时,应用程序关闭。 |
OnMainWindowClose | 启动窗体关闭或调用Application对象的Shutdown()方法时,引用程序关闭。(和C#的Windows应用程序的关闭模式比较类似,可应用为主窗体关闭时,应用程序关闭) |
OnExplicitShutDown | 只有在调用Application对象的Shutdown()方法时,应用程序才会关闭。 |
如何设置关闭选项
1.方法一
在项目的App.xaml文件中s设置
<Application x:Class="StudentManagerWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StudentManagerWPF"
Startup="Application_Startup" ShutdownMode="OnMainWindowClose"
>
<Application.Resources> </Application.Resources>
</Application>
2.方法二
在C#后台代码设置,在App.xaml.cs文件中修改,但是注意此设置必须写在app.Run()方法之前
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;