我有一个MergedDictionaries
and DateTemplate
里面一个ResourceDictionary
一切都很好,直到我添加了一个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
.
该错误告诉您问题所在:
<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 中设置属性。任何没有的东西.
是内容,必须出现在任何属性设置器下方。
Note:反之亦然,如果您喜欢这种方式,属性也可以位于所有内容下方
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)