gpt4 book ai didi

c# - WPF 错误 : Property elements cannot be in the middle of an element's content. 它们必须在内容之前或之后

转载 作者:太空狗 更新时间:2023-10-30 00:31:23 26 4
gpt4 key购买 nike

我在 ResourceDictionary 中有一个 MergedDictionaries 和一个 DateTemplate,在我添加一个 Converter 之前一切都很好:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTry">

<local:IsEnabledConverter x:Key="isEnabled"/> <===== causes problem

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml" />
</ResourceDictionary.MergedDictionaries>

<DataTemplate x:Key="fileinfoTemplate" DataType="{x:Type local:MyFileInfo}">
... template stuff
</DataTemplate>

</ResourceDictionary>

添加 Converter 行会在 DataTemplate 行导致此错误:

Property elements cannot be in the middle of an element's content. They must be before or after the content.

为什么会导致这个错误?

请注意,如果我注释掉 MergedDictionaries,代码会编译并且 Converter 工作正常。

最佳答案

错误告诉您问题所在:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTry">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml" />
</ResourceDictionary.MergedDictionaries>

<!-- Move this here -->
<local:IsEnabledConverter x:Key="isEnabled"/>

<DataTemplate x:Key="fileinfoTemplate" DataType="{x:Type local:MyFileInfo}">
... template stuff
</DataTemplate>

</ResourceDictionary>

您试图在资源字典上设置属性之前放置内容。该错误表示“属性元素”(例如 ResourceDictionary.MergedDictionaries)不能位于元素“内容”(例如您的数据模板/转换器等)的中间

任何带有点 . 的内容都必须出现在元素的顶部,因为您实际上是在 XAML 中设置属性。任何没有 . 的内容都是内容,必须出现在任何属性 setter 下方。

注意:反之亦然,如果您愿意,属性也可以位于所有内容下方

关于c# - WPF 错误 : Property elements cannot be in the middle of an element's content. 它们必须在内容之前或之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26524787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com