WPF:绑定条件与物业,XamlParseException无论是使用 [英] WPF: Condition Binding versus Property, XamlParseException using either
问题描述
我有一个条件
麻烦了 MultiTrigger
。如果我做了以下内容:
<条件绑定={绑定的RelativeSource = {的RelativeSource
AncestorType = {X:类型的ListView}}}属性=IsEnabledVALUE =真/>
然后我得到这个异常:
条件不能同时使用属性和绑定。在标记文件对象System.Windows.Condition错误
块引用>然而,当我做到以下几点:
<条件绑定={绑定的RelativeSource = {的RelativeSource
AncestorType = {X:类型的ListView}},路径= IsEnabled}VALUE =真/>然后我得到这个异常:
必须指定属性和值的触发。在标记文件对象System.Windows.Condition错误
块引用>怎么办?如果它的事项,这里的整个触发:
< MultiTrigger>
< MultiTrigger.Conditions>
<条件绑定={绑定路径= IsSelected}VALUE =真/>
<条件绑定={绑定路径= ItemsControl.AlternationIndex}
值=0/>
<条件绑定={绑定的RelativeSource = {的RelativeSource
AncestorType = {X:类型的ListView}},路径= IsEnabled}
值=真/>
< /MultiTrigger.Conditions>
< setter属性=背景
VALUE ={StaticResource的evenSelected}/>
< setter属性=BorderBrush
VALUE ={StaticResource的evenSelectedBorder}/>
< / MultiTrigger>
解决方案在这种情况下,API是混乱的。
条件
用于两种不同类型的多触发器,和所使用的特性是不同的。当使用MultiTrigger
,你会使用属性
和值
属性。当使用MultiDataTrigger
(这是你所需要的),您可以指定一个绑定
和值
。所以,如果你只是切换您的code使用MultiDataTrigger
,你会好走:< MultiDataTrigger>
< MultiDataTrigger.Conditions>
<条件绑定={绑定路径= IsSelected}VALUE =真/>
<条件绑定={绑定路径= ItemsControl.AlternationIndex}
值=0/>
<条件绑定={绑定的RelativeSource = {的RelativeSource
AncestorType = {X:类型的ListView}},路径= IsEnabled}
值=真/>
< /MultiDataTrigger.Conditions>
< setter属性=背景
VALUE ={StaticResource的evenSelected}/>
< setter属性=BorderBrush
VALUE ={StaticResource的evenSelectedBorder}/>
< / MultiDataTrigger>I'm having trouble with a
Condition
for aMultiTrigger
. If I do the following:<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListView}}}" Property="IsEnabled" Value="True"/>
Then I get this exception:
Condition cannot use both Property and Binding. Error at object 'System.Windows.Condition' in markup file
However, when I do the following:
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListView}}, Path=IsEnabled}" Value="True"/>
Then I get this exception:
Must specify both Property and Value for Trigger. Error at object 'System.Windows.Condition' in markup file
What gives? If it matters, here's the entire trigger:
<MultiTrigger> <MultiTrigger.Conditions> <Condition Binding="{Binding Path=IsSelected}" Value="True"/> <Condition Binding="{Binding Path=ItemsControl.AlternationIndex}" Value="0"/> <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListView}}, Path=IsEnabled}" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" Value="{StaticResource evenSelected}" /> <Setter Property="BorderBrush" Value="{StaticResource evenSelectedBorder}" /> </MultiTrigger>
解决方案The API in this case is confusing.
Condition
is used for two different types of multi-triggers, and the properties used are different. When usingMultiTrigger
, you will use theProperty
andValue
properties. When usingMultiDataTrigger
(which is what you need), you specify aBinding
and aValue
. So, if you just switch your code to use aMultiDataTrigger
, you'll be good to go:<MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=IsSelected}" Value="True"/> <Condition Binding="{Binding Path=ItemsControl.AlternationIndex}" Value="0"/> <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListView}}, Path=IsEnabled}" Value="True"/> </MultiDataTrigger.Conditions> <Setter Property="Background" Value="{StaticResource evenSelected}" /> <Setter Property="BorderBrush" Value="{StaticResource evenSelectedBorder}" /> </MultiDataTrigger>
这篇关于WPF:绑定条件与物业,XamlParseException无论是使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!