XAML/UWP用户控件问题

juud5qan  于 2023-02-27  发布在  其他
关注(0)|答案(1)|浏览(174)

我正在使用Visual Studio 22与UWP项目。
我尝试在项目中创建一个具有自定义依赖项属性“Label”的用户控件“Logo”。
但当我尝试在MainPage.xaml上使用此控件时,我收到以下错误消息:The XAML Binary Format (XBF) generator reported syntax error '0x09ca'
自定义控件的XAML:

<UserControl
    x:Class="MyApp.UI.Images.Logo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    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"
    >

    <Grid>
        <Image
            x:Name="ImageLogo"

            />
    </Grid>
</UserControl>

用户控件的代码隐藏:

namespace MyApp.UI.Images
{
    public sealed partial class Logo : UserControl
    {
        public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
            "Label",
            typeof(string),
        typeof(Logo),
        new PropertyMetadata(null)
            );

        public string Label
        {
            get
            {
                return (string)GetValue(LabelProperty);
            }
            set
            {
                SetValue(LabelProperty, value);
            }
        }
        
        public Logo()
        {
            this.InitializeComponent();
        }
    }
}

MainPage.xaml

<Page xmlns:my="using:Microsoft.UI.Xaml.Controls"  
    x:Class="MyApp.Pages.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:UI.Images="using:MyApp.UI.Images"
    >
    <Grid>
.....
        <UI.Images:Logo/>
....
   </Grid>
</Page>
zzzyeukh

zzzyeukh1#

我发现了问题所在:
MainPage.xaml中的命名空间xmlns:UI.Images就是它。

`<Page xmlns:my="using:Microsoft.UI.Xaml.Controls"  
x:Class="MyApp.Pages.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UI.Images="using:MyApp.UI.Images"
>
<Grid>
    <UI.Images:Logo/>
</Grid>

将其重命名为xmlns:Logo后,它工作正常

相关问题