如何使用Grid.Row属性作为MultiDataTrigger条件的数据绑定路径? [英] How can I use Grid.Row Property as a DataBinding Path for a MultiDataTrigger Condition?
问题描述
我想为TextBox设置一个MultiDataTrigger,如下面的代码所示.
I'd like to set a MultiDataTrigger for a TextBox as shown in the code below.
如果我在后面的代码中定义的IsNormal属性为false,并且TextBox位于网格的第二行,则其IsEnabled应该为false.
If IsNormal property, which I defined in the code-behind, is false and the TextBox is in the 2nd row of a Grid, IsEnabled of it should be false.
但是,有关Grid.Row的条件无法正常工作.
However, the Condition regarding the Grid.Row does not work properly.
您能告诉我在这种情况下如何使用Grid.Row属性作为绑定路径吗?
Could you tell me how it is possible to use a Grid.Row property as a binding path in this case?
<Style TargetType="TextBox">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=IsNormal}"
Value="False"/>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Grid.Row}"
Value="2"/>
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="False"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
推荐答案
Grid.Row
是附加属性,因此应如下所示:
Grid.Row
is an attached property, so it should be like this:
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Grid.Row)}"
Value="2"/>
使用(OwnerClass.AttachedProperty)
表示OwnerClass
的AttachedProperty
的路径.
这篇关于如何使用Grid.Row属性作为MultiDataTrigger条件的数据绑定路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!