WPF - 编译错误:模板节中不支持类型为“PropertyArrayStart”的标记 [英] WPF - Compilation error: Tags of type 'PropertyArrayStart' are not supported in template sections

查看:663
本文介绍了WPF - 编译错误:模板节中不支持类型为“PropertyArrayStart”的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我不会只是发布一个错误消息在SO,但在Google搜索只找到一个命中后,我想我至少打开这个错误这里的SO的地板。

Ordinarily I wouldn't just post an error message on SO, but after a Google search only found one hit, I thought I'd at least open the floor for this error here on SO.

我有一个自定义控件 Sparkline ,它的依赖属性为 Values code> unit [] 。下面是一个我在 DataTemplate 中使用它的示例:

I have a custom control called Sparkline with a dependency property called Values of type unit[]. Here's an example where I use it in a DataTemplate:

<DataTemplate DataType="{x:Type Activity:ActivityHistory}">
    <Controls:Sparkline Grid.Column="1" Values="{Binding Path=Values}" />
</DataTemplate>

此代码无法编译。我收到错误讯息:

This code doesn't compile. I receive the error message:


模板部分不支持类型为PropertyArrayStart的标签。

Tags of type 'PropertyArrayStart' are not supported in template sections.

行/列号表示 Values 属性的开始。

The line/column numbers indicate the start of the Values attribute.

这真的引发了我。在Google上搜索时返回了一个结果其中 John_C 完全相同问题。不幸的是,他的解决方案涉及将控制移动到单独的组件。好了,我的已经在一个单独的程序集。我猜猜是别的东西在玩。

This has really thrown me. Searching on Google returned one result where John_C hit exactly the same issue. Unfortunately, his solution involved moving the control to a separate assembly. Well, mine's already in a separate assembly. My guess is that something else is at play.

我从来没有听说过 PropertyArrayStart 。搜索只返回一些与XAML序列化相关的页面。有趣的东西,但没有太多帮助。

I've never heard of PropertyArrayStart. Searching for that only return a few pages related to XAML serialisation. Interesting stuff, but not much help.

想想,我不能想到在框架中有任何依赖属性有数组类型。这是允许的吗?

Thinking about it, I can't think of any dependency properties in the framework that have array types. Is this allowed?

我也试过对 Binding 使用嵌套元素而不是标记扩展。 p>

I also tried using a nested element instead of a markup extension for the Binding.

<DataTemplate DataType="{x:Type Activity:ActivityHistory}">
    <Controls:Sparkline Grid.Column="1">
        <Controls:Sparkline.Values>
            <Binding Path="Values"/>
        </Controls:Sparkline.Values>
    </Controls:Sparkline>
</DataTemplate>

...还是没有运气。

...still no luck.

任何想法欢迎!

推荐答案

这是一个可怕的27分钟...:)

It's been an eventful 27 minutes... :)

将依赖属性的类型从 unit [] 更改为 IList< unit> 解决了问题。最好的是,它没有请求许多代码更改,因为数组已经实现了该接口。

Changing the dependency property's type from unit[] to IList<unit> solved the problem. Best of all, it didn't requite many code changes as the array already implements that interface.

我不知道是否通过接口调度到数组)较慢。我的猜测是肯定的。

I'm not sure whether dispatching to the array via the interface (callvirt) is slower. My guess is yes.

原来的错误消息暗示有一些事情,我不太明白。我会接受任何解释正确的答案。

The original error message hints that there's something going on here that I don't quite understand. I'll accept any answer that explains it properly.

这篇关于WPF - 编译错误:模板节中不支持类型为“PropertyArrayStart”的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆