Hi Cedric,
the best way is to use MVVM and Binding to properties in ViewModel. Try following demo:
<Window x:Class="WpfApp1.Window090"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp090"
mc:Ignorable="d"
Title="cedric-6087_211215" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="450" />
</Grid.RowDefinitions>
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="VerticalAlignment" Value="Center" />
<Style.Triggers>
<DataTrigger Binding="{Binding LeftCheckBox}" Value="True">
<Setter Property="Background" Value="White" />
</DataTrigger>
<DataTrigger Binding="{Binding LeftCheckBox}" Value="True">
<Setter Property="Background" Value="Black" />
</DataTrigger>
<DataTrigger Binding="{Binding RightCheckBox}" Value="True">
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Grid.Resources>
<Style TargetType="CheckBox">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</Grid.Resources>
<CheckBox Grid.Column="0" Content="LEFT CHECKBOX - CLICK ME" IsChecked="{Binding LeftCheckBox}">
<CheckBox.Style>
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Foreground" Value="White" />
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
<CheckBox Grid.Column="1" Content="RIGHT CHECKBOX - PASSIVE" IsChecked="{Binding RightCheckBox}">
<CheckBox.Style>
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid}, Path=Background}" Value="Black">
<Setter Property="Foreground" Value="White" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid}, Path=Background}" Value="White">
<Setter Property="Foreground" Value="Black" />
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
</Grid>
</Window>
ViewModel:
namespace WpfApp090
{
public class ViewModel
{
public bool LeftCheckBox { get; set; }
public bool RightCheckBox { get; set; }
}
}
Result: