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

时间:2016-08-20 16:08:31

标签: uwp uwp-xaml

我正在创建一个针对Windows周年纪念版的新UWP空白应用项目。这是我唯一页面的标记(默认模板名为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的声明时,此错误消失。有没有人知道为什么我得到这个?所有帮助赞赏。谢谢!

3 个答案:

答案 0 :(得分:9)

看起来你的xaml中没有空白的DataTemplate元素。我能够让你的例子与下面的一起工作:

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

答案 1 :(得分:2)

(我对Sergei的答案的评论对于一些人来说非常方便,所以我将其推广到一个答案,使其更加明显)

我遇到了同样的问题,我的DataTemplate并非空白。它虽然在App.xaml中定义。只需将其移动到被引用的位置并删除x:Key属性即可使其正常工作。

答案 2 :(得分:0)

除了数据模板不是空白之外,我遇到了同样的问题。我发现您不能将数据模板保留为空白,并且如果您尝试在app.xaml中合并的资源字典中使用x:Type,那么它也不起作用。 该链接说明了如何x:bind绑定到资源词典中:Resource dictionaries with {x:Bind}

相关问题