<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="CheckBox Demonstration" Margin="0,20,10,20"
FontFamily="Verdana" FontSize="18" FontWeight="Bold"
Foreground="#FF5C9AC9" Grid.Row="0"/>
<!-- two state CheckBox -->
<CheckBox x:Name="cb1" Grid.Row="1" Content="Two State CheckBox"
Checked="HandleCheck" Unchecked="HandleUnchecked" Margin="5,0,0,0" />
<TextBlock x:Name="text1" Grid.Row="2" Margin="5,0,0,0" />
<!-- three state CheckBox -->
<CheckBox x:Name="cb2" Grid.Row="3" Content="Three State CheckBox" IsThreeState="True" Checked="HandleCheck"
Indeterminate="HandleThirdState" Unchecked="HandleUnchecked" Margin="5,10,0,0" />
<TextBlock x:Name="text2" Grid.Row="4" Margin="5,0,0,0" />
...
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="CheckBox Demonstration" Margin="0,20,10,20"
FontFamily="Verdana" FontSize="18" FontWeight="Bold"
Foreground="#FF5C9AC9" Grid.Row="0"/>
<!-- two state CheckBox -->
<CheckBox x:Name="cb1" Grid.Row="1" Content="Two State CheckBox"
Checked="HandleCheck" Unchecked="HandleUnchecked" Margin="5,0,0,0" />
<TextBlock x:Name="text1" Grid.Row="2" Margin="5,0,0,0" />
<!-- three state CheckBox -->
<CheckBox x:Name="cb2" Grid.Row="3" Content="Three State CheckBox" IsThreeState="True" Checked="HandleCheck"
Indeterminate="HandleThirdState" Unchecked="HandleUnchecked" Margin="5,10,0,0" />
<TextBlock x:Name="text2" Grid.Row="4" Margin="5,0,0,0" />
private void HandleCheck(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
if (cb.Name == "cb1")
text1.Text = "Two state CheckBox checked.";
else
text2.Text = "Three state CheckBox checked.";
}
private void HandleUnchecked(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
if (cb.Name == "cb1")
text1.Text = "Two state CheckBox unchecked.";
else
text2.Text = "Three state CheckBox unchecked.";
}
private void HandleThirdState(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
text2.Text = "Three state CheckBox indeterminate.";
}