介绍
就像每一个窗口对应一个Window类一样,每一个WPF的应用程序对应一个Application类
生命周期
创建
WPF程序中,Application类的创建是由App.xaml中完成的,具体的代码如下
<Application x:Class="TestProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Novc.ViPlex.Express" DispatcherUnhandledException="Application_DispatcherUnhandledException"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Novc.ViPlex.Express.Views;component/Themes/Converters.xaml"/>
<ResourceDictionary Source="/Novc.ViPlex.Express.Views;component/Themes/Default/Generic.xaml"/>
<ResourceDictionary Source="/Novc.ViPlex.Express.Views;component/Language/Language.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
其中比较关键的是指定了StartupUri
关闭
- 在xaml中可以设置ShutdownMode
- 手动关闭应用程序需要:Application.Shutdown()