How can I use Grid.Row Property as a DataBinding Path for a MultiDataTrigger Condition?

感情迁移 提交于 2019-12-11 10:33:32

问题


I'd like to set a MultiDataTrigger for a TextBox as shown in the code below.

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.

However, the Condition regarding the Grid.Row does not work properly.

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>

回答1:


Grid.Row is an attached property, so it should be like this:

<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Grid.Row)}"
                       Value="2"/>

Use (OwnerClass.AttachedProperty) to indicate path to AttachedProperty of the OwnerClass.



来源:https://stackoverflow.com/questions/32885623/how-can-i-use-grid-row-property-as-a-databinding-path-for-a-multidatatrigger-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!