菜鸟求助,UWP如何取消用户关闭程序
uwp吧
全部回复
仅看楼主
level 13
ihc308 楼主
比如说我做一个记事本程序,如果用户没有保存就点右上的×关闭程序,我就弹窗问是否保存之类的,而不是直接退出。
2017年07月26日 04点07分 1
level 1
我搜了一下,好像没办法。查了一下msdn的提
这段话有些参考意义:
There is no closing event in Universal Windows apps like Form.FormClosing Event. But if you want to do something before you leaving a page, you can use Page.OnNavigatingFrom method. OnNavigatingFrom can be used to cancel a navigation by setting a Cancel property in the event data from your handler.
And if you want to do something before you closing your app, you can use Application.Suspendingevent. There's no special event to indicate that the user closed the app. After an app has been closed by the user, it's first suspended and then terminated, and enters the NotRunning state. Note that if an app does not return from the suspending event within 5 seconds , Windows assumes that the app has stopped responding and terminates it. For more information at App lifecycle.
1、UWP里面没有Close事件
2、当你关闭应用,会调用Application.Suspending事件,APP挂起,然后被kill掉
(你可以试一下:打开任务管理器看一眼,关闭一个应用后,会在后台短暂停留几秒
你可以参考win10 app 的生命周
关于在应用挂起时保存数据,可以参考MSDN的Suspending API:
注:MSDN关键词搜索:Handle app suspend、Closing event in Universal Windows apps 、Windows 10 universal Windows platform (UWP) app lifecycle
连续超过10次,被百度吞回复,我就不填写链接了,你自己去MSDN查吧
2017年07月26日 08点07分 9
谢谢你,我也找到了,正在看
2017年07月26日 08点07分
level 7
uwp应用貌似都是自动保存的
2017年07月30日 09点07分 10
1