UWP on desktop closed by top X button - no event

后端 未结 4 1627
温柔的废话
温柔的废话 2020-12-01 18:06

An UWP app which runs on desktop can be closed from the top X button but it doesn\'t have any event for it. It is known that on phones and tablets an app should rely on

4条回答
  •  无人及你
    2020-12-01 18:39

    This code helps you -

    In App.xaml.cs

    ...
    using Windows.ApplicationModel;
    ...
    
    public App()
    {
        InitializeComponent();            
        this.Suspending += OnSuspending;
    }
    ...
    private void OnSuspending(object sender, SuspendingEventArgs e)
    {
        var deferral = e.SuspendingOperation.GetDeferral();
        //Add your logic here, if any
        deferral.Complete();
    }
    

    Thanks!!!

提交回复
热议问题