Windows 11 - Can I toggle SystemNavigationManagerPreview CloseRequested ?

Fiederer, Jens JF 20 Reputation points
2023-03-03T14:29:56+00:00

We have an app in the Microsoft store that has the confirmAppClose restricted capability.

As a result, when the user puts the app in the background and then tries to close it from the taskbar, nothing happens immediately (the app successfully closes, of course, when the user puts it in the foreground).

Ideally, we would like a close request to actually put the app in the foreground, so that the close can happen automatically after we clean up, but I suspect this is not currently possible (is that capability maybe in the works?)

Otherwise, we would like to be able to hook and unhook the CloseRequested event, so that at least we can get immediate responsiveness when there isn't anything to clean up!

But I have a test application in which I do

                prev = SystemNavigationManagerPreview.GetForCurrentView();
                prev.CloseRequested += PsaAccounting_CloseRequested;

and then later, in response to a button

            prev.CloseRequested -= PsaAccounting_CloseRequested;

Yet even after pressing that button and seemingly unhooking the event (I checked with breakpoints in debug mode) the application does not close immediately, and the PsaAccounting_CloseRequested method is called (again, I checked with breakpoints in debug mode).

Why is this happening?

How can I make this stop?

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Roy Li - MSFT 31,551 Reputation points Microsoft Vendor
    2023-03-17T01:19:29.54+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Based on the document: SystemNavigationManagerPreview.CloseRequested Event, it has been mentioned that ClosedRequested events will not be raised for windows that are non-visible. So it is expected behavior that the event will not fire when close it from the taskbar.

    And I've made a test about subscribe and unsubscribe the CloseRequested event. On my side, when I click a button to unsubscribe the event, and then close the app by click the X button, the event will not fire again.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful