(1)跟目录导入图片
(2)在App.xaml.cs文件中输入以下代码
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); SplashScreen splashScreen = new SplashScreen("EzGUwC4VEAIxi6E.jpg"); splashScreen.Show(true); }
(1)在以下输入StartupUri="MainWindow.xaml" 是初始窗口的文件名
<Application x:Class="DP.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:DP" ShutdownMode="OnMainWindowClose" StartupUri="MainWindow.xaml"> </Application>
(1)在以下输入ShutdownMode="OnMainWindowClose"关闭模式,一种有3种 OnlastWindowClose、OnExplicitShutdown(强制调用 Application.shoutdown)、OnMainWindowClose
<Application x:Class="DP.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:DP" ShutdownMode="OnMainWindowClose" StartupUri="MainWindow.xaml"> </Application>
在App.xaml.cs文件中输入以下代码
protected override void OnExit(ExitEventArgs e) { base.OnExit(e); MessageBoxResult messageBoxResult = MessageBox.Show("dfsf"); MessageBox.Show("sdfsfsd"); }
在App.xaml.cs文件中输入以下代码
protected override void OnSessionEnding(SessionEndingCancelEventArgs e) { base.OnSessionEnding(e); MessageBoxResult messageBoxResult = MessageBox.Show("dfsf"); MessageBox.Show("sdfsfsd"); if(messageBoxResult == MessageBoxResult.No) e.Cancel = true; }
DispatcherUnhandedException事件
// 程序启动时注册DispatcherUnhandledException事件 protected override void OnStartup(StartupEventArgs e) { Current.DispatcherUnhandledException += AppDispatcherUnhandledException; base.OnStartup(e); } protected override void OnExit(ExitEventArgs e) { Current.DispatcherUnhandledException -= AppDispatcherUnhandledException; base.OnExit(e); } private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { //设置异常已处理 e.Handled = true; //异常处理 new ExceptionViewModel(e.Exception); }