简体   繁体   English

我如何单击UWP上的“退出”按钮?

[英]How do I know when I clicked the Exit button on the UWP?

I want to delete my img what i made, when my program is ended. 程序结束时,我想删除自己制作的img。

(It means when user click the exit button.) (这意味着用户单击退出按钮。)

Click this button. 单击此按钮。 exit_btn_img

Or, when user click the exit button, then I want to show the popup window. 或者,当用户单击退出按钮时,我想显示弹出窗口。

So User can save their img before the program is ended. 因此,用户可以在程序结束之前保存其img。

But I couldn't find that way. 但是我找不到那条路。

Is this impossible way? 这是不可能的方法吗?

Please tell me anything!! 请告诉我任何事情! Thanks for reading this. 感谢您阅读本文。

Take a look at application lifecycle article . 看一下应用程序生命周期文章 You shouldn't add blocking code to the app suspended event. 您不应该在应用程序暂停事件中添加阻止代码。 You need to silently save its state and restore state once your app gets back to active state as if it was not closed at all. 一旦您的应用恢复为活动状态,就好像它根本没有关闭一样,您需要静默保存其状态并恢复状态。

Regarding close button from ms docs : 关于ms docs的关闭按钮:

There is not an event to indicate that the user closed the app. 没有事件表明用户已关闭该应用程序。 When an app is closed by the user, it is first suspended to give you an opportunity to save its state. 当用户关闭某个应用程序时,该应用程序首先会被暂停,以使您有机会保存其状态。 In Windows 8.1 and later, after an app has been closed by the user, the app is removed from the screen and switch list but not explicitly terminated. 在Windows 8.1和更高版本中,用户关闭应用程序后,该应用程序将从屏幕和切换列表中删除,但未明确终止。

Closed-by-user behavior: If your app needs to do something different when it is closed by the user than when it is closed by Windows, you can use the activation event handler to determine whether the app was terminated by the user or by Windows. 使用者关闭行为:如果您的应用程式在使用者关闭时需要做的动作与Windows关闭时有所不同,您可以使用启动事件处理常式来判断应用程式是由使用者终止还是由Windows终止。 See the descriptions of ClosedByUser and Terminated states in the reference for the ApplicationExecutionState enumeration. 有关ApplicationExecutionState枚举的信息,请参见参考中ClosedByUser和Terminated状态的描述。

See the accepted answer of this question. 请参阅问题的公认答案。

And to understand more how you can incorporte this in your application you can also refer to this blog post . 要了解更多如何在您的应用程序中实现此功能,您还可以参考此博客文章

Basically you need 2 aspects to achieve this: 基本上,您需要两个方面来实现此目的:

  1. confirmAppClose restricted capability. ConfirmAppClose受限功能。
  2. an event to handle the app closing. 处理应用程序关闭的事件。 SystemNavigationManagerPreview.GetForCurrentView().CloseRequested SystemNavigationManagerPreview.GetForCurrentView()。CloseRequested

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM