UWP:在DataTemplate上使用x:DataType属性时编译错误



我正在创建一个新的UWP空白应用程序项目,目标是Windows的周年纪念版。这是我唯一一个页面(名为MainPage)的标记。Xaml(默认模板):

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

类BindyThing在CS文件中声明如下:

namespace App1
{
     public class BindyThing
     {
     }
}

从上面的标记中可以看到,我正在尝试创建一个DataTemplate来呈现BindyThing。然而,当我编译时,我得到以下错误:

The XAML Binary Format (XBF) generator reported syntax error '0x09C4' : Property Not Found

当我注释掉DataTemplate的声明时,这个错误就消失了。有人知道我为什么会得到这个吗?感谢所有的帮助。谢谢你!

看起来你的xaml中不能有一个空白的DataTemplate元素。我能够让您的示例与以下内容一起工作:

<DataTemplate x:Key="MyDataTemplate" x:DataType="local:BindyThing">
    <TextBlock></TextBlock>
</DataTemplate>

(我对Sergei的回答的评论对一些人来说很方便,所以我把它提升为一个答案,让它更明显)

我也面临同样的问题,我的DataTemplate不是空白的。但它是在App.xaml中定义的。简单地移动到它被引用的地方,并删除x:Key属性使其工作良好。

我有同样的问题,只是我的数据模板不是空白的。我发现你不能有数据模板空白,如果你尝试使用x:在app.xaml中合并的资源字典中键入,它也不会工作。这个链接解释了如何在资源字典中使用x:bind: {x: bind}

最新更新