简体   繁体   中英

Disable titlebar “X” - close button

This question got repeated a few times already in the past and the answer was that it is not possible yet. I wondered if it is possible by now?

UWP on desktop closed by top X button - no event

the top answer here says it is possible but I had trouble in making it work. I think I need a reference for SystemNavigationManagerPreview or I need to add

<Capabilities> <Capability Name="internetClient" /> <rescap:Capability Name="confirmAppClose"/> </Capabilities>

in the manifest but I could not figure it on how to do this.

Yes, you are on the right path with this capability. You need to handle the CloseRequested event in order to override what happens when the user clicks the 'X'.

https://docs.microsoft.com/en-us/uwp/api/windows.ui.core.preview.systemnavigationmanagerpreview.closerequested

Elsewhere you say you're using VS2015, which can target only up to the Anniversary Update (Build 14393). SystemNavigationManagerPreview.CloseRequested was new for the Creators Update (Build 15603). You'll need to use VS2017 to set your target version high enough to support CloseRequested.

SystemNavigationManagerPreview docs:

Windows 10 requirements

Device family Windows 10 Creators Update (introduced v10.0.15063.0)

Choose a UWP version docs:

Build 15063 (Creators Update, version 1703)

Please note that you must be using Visual Studio 2017 in order to target this version of Windows.

Once you're on Visual Studio 2017 you can set the minimum version in the Project Properties' Application section, and then you'll be able to set the capabilities in your manifest as Stefan and the linked post describe.

For more on defining restricted capabilities see the Restricted Capabilities documentation. In particular, you'll need to define xmlns:rescap and then add it to the IgnorableNamespaces before you can set the capability itself with the code in your question.

<?xml version="1.0" encoding="utf-8"?>
<Package
    ...
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    IgnorableNamespaces="... rescap">
...
<Capabilities>
    <rescap:Capability Name="confirmAppClose"/>
</Capabilities>
</Package>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM