1

I have done some researching and I haven't found much that is useful for UWP. When the 'X' is hit on the window I need to call a function before the application actually closes. I can't seem to find any sources that deal with MVVM Cross and UWP. It seems that there may be a way but there is just simply a lack of resources online. I am really just looking to be pointed in the right direction.

3 Answers3

4

When you create a Blank App and go to App.xaml.cs you should see an event in the end of the file OnSuspending

See Below

/// <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();
}

This is what you are looking for.

AVK
  • 3,893
  • 1
  • 22
  • 31
1

You can use the confirmAppClose capability to override the close button. But, to use this capability, you need to add it on your appxmanifest, AND, ask Microsoft to get the certification.

Override Close Box on Window 10 Universal Apps UWP

Mamoru Satoh
  • 2,670
  • 23
  • 23
0

I'm not sure what you mean by deal with MVVM Cross. To handle or call a function before application close/deactivate you can call following events:

Window.Current.Activated += (s, e) =>
{
    //closed, activated, deactivate
};
Window.Current.Closed += (ss, ee) =>
{
    //closed
};
AVK
  • 3,893
  • 1
  • 22
  • 31
Nghia Nguyen
  • 2,585
  • 4
  • 25
  • 38
  • This is not going to work. I don't think you can monitor the `Closed` event on the **main** window. – Justin XL Jul 14 '17 at 12:57
  • I tested and it works for me, not sure what you mean by cannot monitor Closed event? – Nghia Nguyen Jul 14 '17 at 18:54
  • `Activated` should work, but `Closed` won't fire... And this question was asking specifically how to handle when the **x** button is clicked – Justin XL Jul 14 '17 at 22:42