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

发布于 2024-07-21 07:57:32 字数 1478 浏览 2 评论 0原文

通常我不会只是在 SO 上发布错误消息,但在 Google 搜索只找到一个结果后,我想我至少应该在 SO 上为这个错误打开空间。

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

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

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

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

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

这真的让我很困惑。 在 Google 上搜索返回一个结果< /a> 其中 John_C 遇到了完全相同的问题。 不幸的是,他的解决方案涉及将控件移至单独的组件。 嗯,我的已经在一个单独的组件中了。 我的猜测是还有其他因素在起作用。

我从未听说过 PropertyArrayStart。 搜索该内容仅返回与 XAML 序列化相关的几个页面。 有趣的东西,但没有多大帮助。

想来想去,我想不出框架中有任何具有数组类型的依赖属性。 这是允许的吗?

我还尝试使用嵌套元素而不是 Binding 的标记扩展。

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

...仍然没有运气。

欢迎任何想法!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2024-07-28 07:57:32

这是多事的 27 分钟...:)

将依赖属性的类型从 unit[] 更改为 IList 解决了问题。 最重要的是,它不需要进行太多代码更改,因为数组已经实现了该接口。

我不确定通过接口(callvirt)分派到数组是否更慢。 我的猜测是肯定的。

原始错误消息暗示这里发生了一些我不太明白的事情。 我会接受任何正确解释的答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文