【WPF】应用程序设置
2022/7/24 14:22:44
本文主要是介绍【WPF】应用程序设置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、WPF应用程序添加splashScreen(初始屏幕)
(1)跟目录导入图片
(2)在App.xaml.cs文件中输入以下代码
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); SplashScreen splashScreen = new SplashScreen("EzGUwC4VEAIxi6E.jpg"); splashScreen.Show(true); }
2、设置应用程序的初始窗口
(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>
3、设置应用程序的关闭方式
(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>
4、应用程序的窗体退出设置
在App.xaml.cs文件中输入以下代码
protected override void OnExit(ExitEventArgs e) { base.OnExit(e); MessageBoxResult messageBoxResult = MessageBox.Show("dfsf"); MessageBox.Show("sdfsfsd"); }
5、计算机注销或关键结束应用程序时设置
在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; }
6、记录应用程序未处理异常
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); }
这篇关于【WPF】应用程序设置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?
- 2024-05-09企业src漏洞挖掘-有意思的命令执行