我可以阻止用户关闭我的 UWP 应用程序吗(不包括结束任务)

Can I stop a user closing my UWP application (Excluding End Task)

我正在设计 UWP 应用程序。按下 "X" (关闭按钮) 我想显示一个弹出窗口说 "You are about to close without saving. Would you like to discard your work?" 并取消关闭如果用户点击 "No"

的事件

我考虑过的另一种方法是完全隐藏 "X"(关闭按钮),以便用户只能使用我自己的关闭按钮关闭它。

我不担心 "End Task" 因为无论如何你都无能为力。

那么是否可以执行以下任一操作:

我知道这在 WPF 中是可能的,但在 UWP 中是否有类似的东西?

据我所知,这是不可能的,您可以对后退按钮执行类似的操作,但不能对关闭按钮执行类似的操作。用户只是终止了该应用程序,您对此无能为力,另请注意,您的应用程序可能已挂起,但用户仍然可以关闭它。

值得一提的是,当用户点击 'X' 时,该应用仍会处理一些事件,例如 Suspending - 因此您仍然有机会保存一些 things/process 一些逻辑。

有关此内容的更多信息,请访问 MSDN - section App Close:

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.