WPF - Compilation error: Tags of type 'PropertyArrayStart' are not supported in template sections

瘦欲@ 提交于 2019-12-12 07:40:07

问题


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.

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:

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

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

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.

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.

Any ideas welcomed!


回答1:


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

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.



来源:https://stackoverflow.com/questions/926486/wpf-compilation-error-tags-of-type-propertyarraystart-are-not-supported-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!