【问题标题】:UWP: Compile error when using x:DataType property on DataTemplateUWP:在 DataTemplate 上使用 x:DataType 属性时出现编译错误
【发布时间】:2016-12-27 15:03:17
【问题描述】:

我正在创建一个针对 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 的声明时,此错误消失。有没有人知道我为什么会得到这个?所有帮助表示赞赏。谢谢!

【问题讨论】:

    标签: uwp uwp-xaml


    【解决方案1】:

    您的 xaml 中似乎不能有空白的 DataTemplate 元素。我能够让您的示例与以下内容一起使用:

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

    【讨论】:

    • 是的,就是这样。不敢相信我没有找到那个。谢谢!
    • 我面临同样的问题,我的DataTemplate 不是空白的。它是在 App.xaml 中定义的。如果我只是将它移动到它被引用的位置并删除x:Key 属性,相同的模板可以正常工作。
    • @dotNET 如果您设法找出问题所在,我会很高兴知道...我也有同样烦人的问题。
    • ^ ... greeeeat o_O
    【解决方案2】:

    (我在 Sergei 的回答中的评论对少数人来说很方便,所以我将其提升为一个答案以使其更明显)

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

    【讨论】:

    • 删除 x:Key 对我来说不是一个选项 :(
    【解决方案3】:

    我遇到了同样的问题,只是我的数据模板不是空白的。我发现你不能将数据模板留空,如果你尝试在 app.xaml 中合并的资源字典中使用 x:Type ,它也不起作用。 这个链接解释了如何 x:bind 代替资源字典:Resource dictionaries with {x:Bind}

    【讨论】:

    • x:DataType 也需要此解决方案,即使您使用x:Bind
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 2015-07-21
    • 2015-04-27
    • 2016-11-20
    • 1970-01-01
    • 2020-09-19
    相关资源
    最近更新 更多