错误 XDG0008:通用 Windows 平台项目不支持 NumberBox
Error XDG0008: NumberBox is not supported in a Universal Windows Platform project
以下代码有一个奇怪的问题:
<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>
创建项目后,在我添加 <NumberBox>
之前没有进行任何更改。会出现三个编译错误:
我尝试更新 NuGet 包:
但是错误依旧。
我该如何修复?
我真的需要一些帮助:/
开发环境:
IDE: Visual Studio 2019
UWP项目目标版本:Windows10,版本1903(10.0; Build
18362)
UWP 项目最低版本:Windows10,版本 1903(10.0;Build 18362)
从这个 document of NumberBox, you can see that the NumberBox is under the Microsoft.UI.Xaml.Controls namespace and applies to WinUI. So as @magicandre1981 said, you need to install Microsoft.UI.Xaml nuget 包并将 Windows UI (WinUI) 主题资源添加到您的 App.xaml 资源。然后在xaml中添加命名空间即可使用
App.xaml:
<Application ...>
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</Application.Resources>
</Application>
.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>
创建自定义控件
<UserControl x:Class="GroceryPriceTracker.Controls.NumberBoxControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:GroceryPriceTracker.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<x:Double x:Key="CWidth">35</x:Double>
</UserControl.Resources>
<Grid Height="{StaticResource CWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="40"></ColumnDefinition>
<ColumnDefinition Width="40"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox InputScope="Number" BorderThickness="1"
Loaded="TextBox_Loaded"
Padding="10,6,10,0"
Height="35"
Style="{StaticResource TextBoxStyleBlack}"></TextBox>
<Grid Grid.Column="1"
BorderBrush="{ThemeResource InkToolbarAccentColorThemeBrush}"
BorderThickness="1"
Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}">
<Button Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}"
Grid.Column="1"
BorderThickness="0"
Background="Transparent">
<FontIcon FontSize="17"
FontFamily="Segoe MDL2 Assets"
Glyph="" />
</Button>
</Grid>
<Grid Grid.Column="2"
Margin="-5,0,0,0"
BorderBrush="{ThemeResource InkToolbarAccentColorThemeBrush}"
BorderThickness="1"
Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}">
<Button Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}"
BorderThickness="0"
Background="Transparent"
Grid.Column="2">
<FontIcon FontSize="17"
FontFamily="Segoe MDL2 Assets"
Glyph="" />
</Button>
</Grid>
</Grid>
</UserControl>
以下代码有一个奇怪的问题:
<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>
创建项目后,在我添加 <NumberBox>
之前没有进行任何更改。会出现三个编译错误:
我尝试更新 NuGet 包:
但是错误依旧。
我该如何修复?
我真的需要一些帮助:/
开发环境:
IDE: Visual Studio 2019
UWP项目目标版本:Windows10,版本1903(10.0; Build 18362)
UWP 项目最低版本:Windows10,版本 1903(10.0;Build 18362)
从这个 document of NumberBox, you can see that the NumberBox is under the Microsoft.UI.Xaml.Controls namespace and applies to WinUI. So as @magicandre1981 said, you need to install Microsoft.UI.Xaml nuget 包并将 Windows UI (WinUI) 主题资源添加到您的 App.xaml 资源。然后在xaml中添加命名空间即可使用
App.xaml:
<Application ...>
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</Application.Resources>
</Application>
.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>
创建自定义控件
<UserControl x:Class="GroceryPriceTracker.Controls.NumberBoxControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:GroceryPriceTracker.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<x:Double x:Key="CWidth">35</x:Double>
</UserControl.Resources>
<Grid Height="{StaticResource CWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="40"></ColumnDefinition>
<ColumnDefinition Width="40"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox InputScope="Number" BorderThickness="1"
Loaded="TextBox_Loaded"
Padding="10,6,10,0"
Height="35"
Style="{StaticResource TextBoxStyleBlack}"></TextBox>
<Grid Grid.Column="1"
BorderBrush="{ThemeResource InkToolbarAccentColorThemeBrush}"
BorderThickness="1"
Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}">
<Button Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}"
Grid.Column="1"
BorderThickness="0"
Background="Transparent">
<FontIcon FontSize="17"
FontFamily="Segoe MDL2 Assets"
Glyph="" />
</Button>
</Grid>
<Grid Grid.Column="2"
Margin="-5,0,0,0"
BorderBrush="{ThemeResource InkToolbarAccentColorThemeBrush}"
BorderThickness="1"
Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}">
<Button Width="{StaticResource CWidth}"
Height="{StaticResource CWidth}"
BorderThickness="0"
Background="Transparent"
Grid.Column="2">
<FontIcon FontSize="17"
FontFamily="Segoe MDL2 Assets"
Glyph="" />
</Button>
</Grid>
</Grid>
</UserControl>