WPF Application Shutdown Mode
2009-11-23 12:59
162 查看
有三种shutdown mode
其中OnMainWindowClose这个挺有用,但首先要知道如何指定MainWindow。
指定MainWindow的两种途径:
1. 在代码中指定
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public App()
{
Window oldMainWindow = this.MainWindow;// Get main window
Window newMainWindow = new Window1();
this.MainWindow = new Window();// Set mainwindow
}
2. 在XAML中指定
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="StartupWindow.xaml"
>
<Application.MainWindow>
<NavigationWindow Source="MainPage.xaml" Visibility="Visible"></NavigationWindow>
</Application.MainWindow>
</Application>
配置Shutdown Mode
这里我们选择OnMainWindowClose:
<Application x:Class="TestApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22
StartupUri="Window1.xaml"
ShutdownMode="OnMainWindowClose"
>
</Application>
Member name | Description |
OnLastWindowClose | An application shuts down when either the last window closes, or Shutdown is called. |
OnMainWindowClose | An application shuts down when either the main window closes, or Shutdown is called. |
OnExplicitShutdown | An application shuts down only when Shutdown is called. |
指定MainWindow的两种途径:
1. 在代码中指定
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public App()
{
Window oldMainWindow = this.MainWindow;// Get main window
Window newMainWindow = new Window1();
this.MainWindow = new Window();// Set mainwindow
}
2. 在XAML中指定
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="StartupWindow.xaml"
>
<Application.MainWindow>
<NavigationWindow Source="MainPage.xaml" Visibility="Visible"></NavigationWindow>
</Application.MainWindow>
</Application>
配置Shutdown Mode
这里我们选择OnMainWindowClose:
<Application x:Class="TestApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22
StartupUri="Window1.xaml"
ShutdownMode="OnMainWindowClose"
>
</Application>
相关文章推荐
- 在Windows EndSession时, WPF的Shutdown()和Winforms的Application.Exit()都不可靠
- WPF中App.xaml中ShutdownMode值设置的区别
- #55 – Application.ShutdownMode
- WPF中App.xaml中ShutdownMode值设置的区别
- WPF中App.xaml中ShutdownMode值设置的区别
- WPF中App.xaml中ShutdownMode值设置的区别
- WPF 中实现 Winfrom 中 Application.DoEvents() 方法
- Application called By IE on Pseudo B/S Mode
- [Prism]Composite Application Guidance for WPF(5)——依赖注入容器
- [Prism]Composite Application Guidance for WPF(6)——服务
- Ultraedit v19.10 打开报错“an error has occurred . the application will be shutdown”
- Handling events in an MVVM WPF application
- How to run WPF - XBAP as Full Trust Application(如何运行WPF -作为完全信任的应用XBAP)
- 让WPF Browser Application自动下载并安装数字证书(转)
- DXWpfApplication 的中文问题
- WPF 学习记录——Application
- #708 – 将文件拖入到WPF应用程序中(Dragging a File Into a WPF Application)
- WPF, WPF Browser Application(XBAP) 和 Silverlight 的区别
- WpfBroserApplication:页面跳转及传值
- GUI application run in console mode