当前上下文中不存在SystemNavigationManagerPreview

时间:2018-11-13 10:25:38

标签: c# uwp package manifest

所以我想尝试在我的UWP应用中禁用“ X”(关闭)按钮。为了测试,我创建了一个新的UWP应用。然后,我去了Visual Studio项目:

\ Visual Studio 2015 \ Projects \ closerequesthandled \ closerequesthandled

并打开Package并编辑以下内容:

首先我添加了xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"rescap

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap mp rescap">

然后我添加了<rescap:Capability Name="confirmAppClose"/>

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

我收到此警告: I Get Following warning

但是我读到这个警告除了警告您之外什么也没有做,所以它仍然应该解决。

然后我将此作为测试添加到MainPage.xaml.cs:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += this.OnCloseRequest;
    }

    private void OnCloseRequest(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
    {
        var x = 0;
    }
}

但是SystemNavigationManagerPreviewSystemNavigationCloseRequestedPreviewEventArgs带有红色下划线:

The name `SystemNavigationManagerPreview` does not exist in the current context

The type or nmespace name `SystemNavigationCloseRequestedPreviewEventArgs` could not be found (are you missing a using directive or an assembly reference?)

我该如何做?

1 个答案:

答案 0 :(得分:1)

在MSDN上,这似乎是相同的question。从您的文件夹中,我们注意到您正在使用Visual Studio 2015,而Visual Studio 2015仅支持14393 SDK。正如Stefan和我的MSDN帖子所述,您必须首先将最低目标版本设置为15063,然后才能使用Windows.UI.Core.Preview API。因此,此特定功能需要Visual Studio 2017。