user1768685
user1768685

Reputation:

Binding with or condition

i have two check boxes and a text box. the text box's IsEnabled property should be binded to both of those check box's IsChecked Properties. if one of check box or both of them are enabled then text box should be enabled. the first solution that came to my mind was multibinding. But it needs another class to do. Is there any easier way to do this?

Upvotes: 1

Views: 423

Answers (2)

Rohit Vats
Rohit Vats

Reputation: 81243

You can do that with two DataTriggers on TextBox Style where you can enable TextBox in case any checkBox is checked.

<CheckBox x:Name="checkBox1"/>
<CheckBox x:Name="checkBox2"/>
<TextBox>
  <TextBox.Style>
    <Style TargetType="TextBox">
      <Setter Property="IsEnabled" Value="False"/>
      <Style.Triggers>
        <DataTrigger Binding="{Binding IsChecked, ElementName=checkBox1}"
                    Value="True">
           <Setter Property="IsEnabled" Value="True"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding IsChecked, ElementName=checkBox2}"
                     Value="True">
           <Setter Property="IsEnabled" Value="True"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </TextBox.Style>
</TextBox>

Upvotes: 2

Christian Sauer
Christian Sauer

Reputation: 10899

I think not - I would really like "and" or "or" expressions in xmal, but they are not provided. I stumpled upon this library, which claims to add them: http://wpfconverters.codeplex.com/ But I never used them extensively.

Upvotes: 0

Related Questions