访问窗口UWP C#上的关闭按钮

时间:2017-07-13 21:43:21

标签: c# uwp mvvmcross

我做了一些研究,但我发现很多对UWP有用的东西。当' X'在窗口上命中我需要在应用程序实际关闭之前调用一个函数。我似乎无法找到任何与MVVM Cross和UWP相关的资源。似乎可能有一种方法,但只是缺乏在线资源。我真的只是想指出正确的方向。

3 个答案:

答案 0 :(得分:4)

当您创建空白应用并转到App.xaml.cs时,您应该会在文件末尾看到一个事件OnSuspending

见下文

/// <summary>
/// Invoked when application execution is being suspended.  Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
    //TODO: Save application state and stop any background activity
    deferral.Complete();
}

这就是你要找的东西。

答案 1 :(得分:1)

您可以使用confirmAppClose功能覆盖关闭按钮。但是,要使用此功能,您需要将其添加到appxmanifest上,并且要求Microsoft获得认证。

Override Close Box on Window 10 Universal Apps UWP

答案 2 :(得分:0)

我不确定与MVVM Cross交易意味着什么。要在应用程序关闭/停用之前处理或调用函数,您可以调用以下事件:

Window.Current.Activated += (s, e) =>
{
    //closed, activated, deactivate
};
Window.Current.Closed += (ss, ee) =>
{
    //closed
};