WPF - 编译错误:不支持模板部分类型“PropertyArrayStart”的标签不支持、模板、错误、类型

2023-09-03 06:43:52 作者:别话春秋

通常情况下,我不会只是张贴在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.

我有一个名为迷你图有一个类型的依赖属性自定义控制单位[] 。这里就是我在使用它的一个例子的的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>

这code不能编译。我收到错误消息:

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

没有在模板部分支持的类型PropertyArrayStart的标签。的

该行/列数字表示的值开始属性。

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

这真的甩了我。谷歌上搜索返回one结果那里 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?

我也尝试过使用嵌套元素,而不是一个标记扩展为绑定

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... :)

改变依赖属性的类型从单元[] 的IList&LT;单元&gt; 解决了这个问题。最重要的是,它并没有报答众多code变化的阵列已经实现了该接口。

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.

我不知道是否通过接口(callvirt)分派到阵列较慢。我的猜测是肯定的。

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.