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

Jam*_*mer 11 uwp uwp-xaml

我正在创建一个针对Windows的Anniversary Build的新UWP Blank App项目.这是我唯一页面的标记(默认模板名为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>
Run Code Online (Sandbox Code Playgroud)

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

namespace App1
{
     public class BindyThing
     {
     }
}
Run Code Online (Sandbox Code Playgroud)

正如您从上面的标记中看到的,我正在尝试创建一个DataTemplate来呈现BindyThing.但是,当我编译时,我收到以下错误:

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

当我注释掉DataTemplate的声明时,此错误消失.有没有人知道为什么我得到这个?所有帮助赞赏.谢谢!

Ser*_*kin 9

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

<DataTemplate x:Key="MyDataTemplate" x:DataType="local:BindyThing">
    <TextBlock></TextBlock>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

  • 我面临同样的问题,我的`DataTemplate`不是空白.它在App.xaml中定义.如果我只是将它移动到被引用的位置并删除`x:Key`属性,则相同的模板工作正常. (8认同)