如果两个文本框中的任何一个处于编辑模式,请禁用按钮

时间:2015-05-17 17:49:45

标签: c# wpf xaml

我试图通过样式来做到这一点。但是所有样本都与验证相关联 - 如何绑定到"编辑模式"

<RibbonButton.Style>
    <Style TargetType="RibbonButton">
        <Setter Property="IsEnabled" Value="False"/>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="Binding Path=(Validation.???EDIT MODE)"
                    </MultiDataTrigger.Conditions>
                </MultiDataTrigger>
            </Style.Triggers>

    </Style>
</RibbonButton.Style>

1 个答案:

答案 0 :(得分:2)

如果通过编辑模式,则表示TextBox具有焦点,您可以使用IsKeyboardFocusWithin属性,并且当IsEnabled=True的此属性为false时触发TextBox <StackPanel> <TextBox x:Name="textBox1"/> <TextBox x:Name="textBox2"/> <RadioButton> <RadioButton.Style> <Style TargetType="{x:Type RadioButton}"> <Setter Property="IsEnabled" Value="False"/> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding ElementName=textBox1, Path=IsKeyboardFocusWithin}" Value="False"/> <Condition Binding="{Binding ElementName=textBox2, Path=IsKeyboardFocusWithin}" Value="False"/> </MultiDataTrigger.Conditions> <Setter Property="IsEnabled" Value="True"/> </MultiDataTrigger> </Style.Triggers> </Style> </RadioButton.Style> </RadioButton> </StackPanel> 1}} ES

IsHitTestVisible