问题
I'm trying to prevent app being closed by clicking the Close box on the App Window. For example, having a text editor with unsaved changes, upon pressing Close Box, I would first display "Do you want to save changes before exiting?"
How can I detect app wanting to close and prevent that from happening?
I'm using C++, and this needs to be for Window 10 Universal Apps UWP. I already know how to do this for Win32.
回答1:
The comments are correct. There is currently no way for a regular Store app to do this.
However, with the Creators Update (and corresponding SDK) we have included a preview API that you can now check out for this functionality:
The Windows.UI.Core.Preview.SystemNavigationManagerPreview class provides a CloseRequested event that an app can mark as handled. For the event to work the app will need to declare the restricted 'confirmAppClose' capability per: https://docs.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations
Please let us know your feedback.
Thanks, Stefan Wick - Windows Developer Platform
来源:https://stackoverflow.com/questions/33685285/override-close-box-on-windows-10-universal-apps-uwp