Reputation: 709
I have two GroupBoxes, which use CheckBoxes A and B as their header. What I want is when B is checked, I want A to be checked as well. A is enabled only when B is unchecked. I have the following code:
<GroupBox>
<GroupBox.Header>
<CheckBox Name="A">
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="IsEnabled" Value="False" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=B, Path=IsChecked}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="False" />
<Setter Property="IsChecked" Value="True" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=B, Path=IsChecked}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
Check Box A
</CheckBox>
</GroupBox.Header>
</GroupBox>
<GroupBox>
<GroupBox.Header>
<CheckBox Name="B">
Check Box B
</CheckBox>
</GroupBox.Header>
</GroupBox>
The problem I have is when I uncheck Check Box B, Check Box A will also be unchecked. What is wrong with my triggers?
Upvotes: 2
Views: 1649
Reputation: 3741
The trigger system will apply a setter when the trigger condition is satisfied. When the trigger condition is not satisfied anymore all trigger's setters are reverted to the original value. This tells you that you can not use triggers for this purpose. Best way to accomplish this is to set it from code behind in Checked
eventhandler.
Upvotes: 2