XMLParseException使用DatateMplate中的绑定在使用非弦乐键访问Ressource时
我有一个用于列表视图的datatemplate。
scriptAded是枚举。
错误来自stackpanel背景属性,因为如果我将其删除,则可以工作。
我的目的是根据建议的属性(也是ScriptAdatiend类型)访问其中一个刷子。
当我运行程序时,将抛出此例外:
system.windows.markup.xamlparseexception :'a“ binding''无法在类型为“ resourcectionary”类型的'deferrableContent'属性上设置。只能在依赖项的依赖项上设置“绑定”。
<DataTemplate>
<DataTemplate.Resources>
<SolidColorBrush x:Key="{x:Static logic:ScriptAdvised.Yes}" Color="Green" Opacity="0.15"/>
<SolidColorBrush x:Key="{x:Static logic:ScriptAdvised.Limited}" Color="Yellow" Opacity="0.15"/>
<SolidColorBrush x:Key="{x:Static logic:ScriptAdvised.No}" Color="Red" Opacity="0.15"/>
</DataTemplate.Resources>
<StackPanel Background="{StaticResource {Binding Advised}}" Orientation="Horizontal">
<CheckBox/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
我不明白,因为我的应用程序中没有任何明确的资源计算。
I have a DataTemplate in a style for ListViews.
ScriptAdvised is an enumeration.
The error comes from the StackPanel background attribute because if I remove it then it works.
My objective here is to access one of the brushes according to the Advised property (which is also of the ScriptAdvised type).
When I run my program, this exception is thrown :
System.Windows.Markup.XamlParseException : 'A 'Binding' cannot be set on the 'DeferrableContent' property of type 'ResourceDictionary'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.'
<DataTemplate>
<DataTemplate.Resources>
<SolidColorBrush x:Key="{x:Static logic:ScriptAdvised.Yes}" Color="Green" Opacity="0.15"/>
<SolidColorBrush x:Key="{x:Static logic:ScriptAdvised.Limited}" Color="Yellow" Opacity="0.15"/>
<SolidColorBrush x:Key="{x:Static logic:ScriptAdvised.No}" Color="Red" Opacity="0.15"/>
</DataTemplate.Resources>
<StackPanel Background="{StaticResource {Binding Advised}}" Orientation="Horizontal">
<CheckBox/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
I don't understand because I don't have any explicit ResourceDictionaries in my application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
样式
与dataTriggers
使用background
基于的值
。这样的事情:Use a
Style
withDataTriggers
to set theBackground
based on the value ofAdvised
. Something like this: