首页 > 解决方案 > “{”后使用的类型“x”必须是标记扩展。错误代码 0x09c6

问题描述

在我的一个用户控件中构建我的解决方案时遇到这个奇怪的错误,该用户控件有一个绑定到模型类的数据模板。

<UserControl
x:Class="MyApp.View.MyMainUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp.View"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:model="using:MyApp.Model.Entity"
Loaded="UserControl_Loaded"
Unloaded="UserControl_Unloaded"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<UserControl.Resources>
    <ResourceDictionary>
        <DataTemplate x:Key="MyTemplate" x:DataType="model:SomeClass" >
        <local:MyUserControl MySomeClass={x:Bind} />
         </DataTemplate>            
    </ResourceDictionary>
</UserControl.Resources>

有趣的是,如果我用 textblock 替换“MyUserControl”,则解决方案构建得很好。我立即用“MyUserControl”替换了文本块,它构建成功。我再次重建,它失败并出现同样的错误。关于这个问题的任何亮点为什么会发生?

这个错误“{”之后使用的类型“x”必须是标记扩展名”是随机 XAML 错误还是特定错误?在什么情况下我会出现错误。如果我可以提醒你们,没有语法错误。以及 MyUserControl 的声明代码,

 <UserControl
x:Class="MyApp.View.MyUserControl"
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">`

`

使用 Visual Studio 19 版本 16.3.8

标签: c#visual-studioxamluwpuwp-xaml

解决方案


您需要将{x:Bind}引号括起来:

        <local:MyUserControl MySomeClass="{x:Bind}" />

推荐阅读