当前上下文中不存在 SystemNavigationManagerPreview
SystemNavigationManagerPreview does not exist in current Context
所以我想尝试禁用我的 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>
我收到这个警告:
但我读到这个警告除了警告你之外没有任何作用,所以它仍然应该有效。
然后我将此作为测试添加到 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;
}
}
但是 SystemNavigationManagerPreview
和 SystemNavigationCloseRequestedPreviewEventArgs
得到红色下划线:
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?)
我怎样才能完成这项工作?
这似乎与 MSDN 上的 question 相同。我们从您的文件夹中注意到您使用的是 Visual Studio 2015,而 Visual Studio 2015 仅支持 14393 SDK。正如 Stefan 和我的 MSDN post 提到的,您必须先将最低目标版本设置为 15063,然后您才能使用 Windows.UI.Core.Preview API。因此,此特定功能需要 Visual Studio 2017。
所以我想尝试禁用我的 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>
我收到这个警告:
但我读到这个警告除了警告你之外没有任何作用,所以它仍然应该有效。
然后我将此作为测试添加到 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;
}
}
但是 SystemNavigationManagerPreview
和 SystemNavigationCloseRequestedPreviewEventArgs
得到红色下划线:
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?)
我怎样才能完成这项工作?
这似乎与 MSDN 上的 question 相同。我们从您的文件夹中注意到您使用的是 Visual Studio 2015,而 Visual Studio 2015 仅支持 14393 SDK。正如 Stefan 和我的 MSDN post 提到的,您必须先将最低目标版本设置为 15063,然后您才能使用 Windows.UI.Core.Preview API。因此,此特定功能需要 Visual Studio 2017。