错误 XDG0008:通用 Windows 平台项目不支持 NumberBox

Jan*_*yee 2 c# xaml uwp uwp-xaml visual-studio-2019

下面的代码有一个奇怪的问题:

<Page
    x:Class="FuckNumberBox.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FuckNumberBox"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <NumberBox x:Name="BeginNumberBox"
                   Header="Enter an integer:" 
                   Value="1" 
                   SpinButtonPlacementMode="Compact" 
                   SmallChange="10"
                   LargeChange="100"/>
    </Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)

IDE 截图

创建项目后,没有进行任何更改,直到我添加了<NumberBox>. 会出现三个编译错误:

错误信息

我尝试更新 NuGet 包:

NuGet 包管理器

但错误仍然在这里。

我该如何修复这个问题?

我真的需要一些帮助:/


开发环境:

  • 集成开发环境:Visual Studio 2019

    UWP 项目目标版本:Windows 10,版本 1903(10.0;Build 18362)

    UWP 项目最低版本:Windows 10,版本 1903(10.0;Build 18362)

Fay*_*SFT 6

从NumberBox的这个文档中,您可以看到NumberBox位于Microsoft.UI.Xaml.Controls命名空间下,适用于WinUI。因此,正如 @magicandre1981 所说,您需要安装Microsoft.UI.Xaml nuget 包并将 Windows UI (WinUI) 主题资源添加到 App.xaml 资源中。然后在xaml中添加命名空间即可使用。

应用程序.xaml:

<Application ...>
    <Application.Resources>
        <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
    </Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)

.xaml:

<Page
    x:Class="FuckNumberBox.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FuckNumberBox"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    xmlns:controls="using:Microsoft.UI.Xaml.Controls">

    <Grid>
        <controls:NumberBox x:Name="BeginNumberBox"
                   Header="Enter an integer:" 
                   Value="1" 
                   SpinButtonPlacementMode="Compact" 
                   SmallChange="10"
                   LargeChange="100"/>
    </Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)