Reputation: 4464
I would like to enable a button when either of the 2 check boxes are checked. When neither of the check boxes are checked, the button should be inactive(IsEnabled = false)
It is possible to bind like this.
IsEnabled="{Binding ElementName=CheckBox Path=IsChecked}"
But it works only for a single checkbox. I want to bind both the check boxes IsChecked properties to the IsEnabled property of button in XAML itself. (I know how to do using property changed in code)
I tried using Multi triggers.
<Button.IsEnabled>
<MultiBinding>
<MultiBinding.Bindings> <Binding ElementName="BlankmeasurementCheckBox" Path="IsChecked"/>
<Binding ElementName="MeasurementCheckBox" Path="IsChecked"/>
</MultiBinding.Bindings>
</MultiBinding>
</Button.IsEnabled>
But it doesn't seem to help. Could you please help me out? Thanks in advance.
Upvotes: 1
Views: 2205
Reputation: 2832
You can make use of MultiDataTrigger
here.
Here is the sample code:
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<CheckBox Name="cbSampleYes" Content="Yes" />
<CheckBox Name="cbSampleSure" Content="I'm sure" />
<Button HorizontalAlignment="Center" Margin="0,20,0,0">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Content" Value="Verified" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=cbSampleYes, Path=IsChecked}" Value="False" />
<Condition Binding="{Binding ElementName=cbSampleSure, Path=IsChecked}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Content" Value="Unverified" />
<Setter Property="IsEnabled" Value="False" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
Upvotes: 3