CheckBox
CheckBox
CheckBox
CheckBox
Class
Definition
Represents a control that a user can select (check) or clear (uncheck). A CheckBox can also report its value as indeterminate.
public : class CheckBox : ToggleButton, ICheckBoxpublic class CheckBox : ToggleButton, ICheckBoxPublic Class CheckBox Inherits ToggleButton Implements ICheckBox// This API is not available in Javascript.
<CheckBox .../>
-or-
<CheckBox>
singleObject
</CheckBox>
-or-
<CheckBox>stringContent</CheckBox>
- Inheritance
-
CheckBoxCheckBoxCheckBoxCheckBox
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Inherited Members
Inherited properties
Inherited events
Inherited methods
Examples
The following example shows two check box controls. The first check box demonstrates the checked and unchecked states. The second check box demonstrates the checked, unchecked, and indeterminate states. You can select the controls to change their appearance and see which state they are in.
<!-- A two-state CheckBox. -->
<CheckBox x:Name="cb1" Content="Two-state CheckBox"
Checked="HandleCheck" Unchecked="HandleUnchecked" />
<TextBlock x:Name="text1" />
<!-- A three-state CheckBox. -->
<CheckBox x:Name="cb2" Content="Three-state CheckBox"
IsThreeState="True" Indeterminate="HandleThirdState"
Checked="HandleCheck" Unchecked="HandleUnchecked" />
<TextBlock x:Name="text2" />
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.";
}
Private Sub HandleCheck(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
If (cb.Name = "cb1") Then
text1.Text = "Two state CheckBox checked."
Else
text2.Text = "Three state CheckBox checked."
End If
End Sub
Private Sub HandleUnchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
If (cb.Name = "cb1") Then
text1.Text = "Two state CheckBox unchecked."
Else
text2.Text = "Three state CheckBox unchecked."
End If
End Sub
Private Sub HandleThirdState(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
text2.Text = "Three state CheckBox indeterminate."
End Sub

<StackPanel>
<CheckBox x:Name="OptionsAllCheckBox" Content="Select all" IsThreeState="True"
Checked="SelectAll_Checked" Unchecked="SelectAll_Unchecked" Indeterminate="SelectAll_Indeterminate"/>
<CheckBox x:Name="Option1CheckBox" Content="Option 1" Margin="24,0,0,0"
Checked="Option_Checked" Unchecked="Option_Unchecked"/>
<CheckBox x:Name="Option2CheckBox" Content="Option 2" Margin="24,0,0,0"
Checked="Option_Checked" Unchecked="Option_Unchecked" IsChecked="True"/>
<CheckBox x:Name="Option3CheckBox" Content="Option 3" Margin="24,0,0,0"
Checked="Option_Checked" Unchecked="Option_Unchecked"/>
</StackPanel>
private void SelectAll_Checked(object sender, RoutedEventArgs e)
{
Option1CheckBox.IsChecked = Option2CheckBox.IsChecked = Option3CheckBox.IsChecked = true;
}
private void SelectAll_Unchecked(object sender, RoutedEventArgs e)
{
Option1CheckBox.IsChecked = Option2CheckBox.IsChecked = Option3CheckBox.IsChecked = false;
}
private void SelectAll_Indeterminate(object sender, RoutedEventArgs e)
{
// If the SelectAll box is checked (all options are selected),
// clicking the box will change it to its indeterminate state.
// Instead, we want to uncheck all the boxes,
// so we do this programatically. The indeterminate state should
// only be set programatically, not by the user.
if (Option1CheckBox.IsChecked == true &&
Option2CheckBox.IsChecked == true &&
Option3CheckBox.IsChecked == true)
{
// This will cause SelectAll_Unchecked to be executed, so
// we don't need to uncheck the other boxes here.
OptionsAllCheckBox.IsChecked = false;
}
}
private void SetCheckedState()
{
// Controls are null the first time this is called, so we just
// need to perform a null check on any one of the controls.
if (Option1CheckBox != null)
{
if (Option1CheckBox.IsChecked == true &&
Option2CheckBox.IsChecked == true &&
Option3CheckBox.IsChecked == true)
{
OptionsAllCheckBox.IsChecked = true;
}
else if (Option1CheckBox.IsChecked == false &&
Option2CheckBox.IsChecked == false &&
Option3CheckBox.IsChecked == false)
{
OptionsAllCheckBox.IsChecked = false;
}
else
{
// Set third state (indeterminate) by setting IsChecked to null.
OptionsAllCheckBox.IsChecked = null;
}
}
}
private void Option_Checked(object sender, RoutedEventArgs e)
{
SetCheckedState();
}
private void Option_Unchecked(object sender, RoutedEventArgs e)
{
SetCheckedState();
}
Remarks
CheckBox is a control that a user can select or clear.

Use the CheckBox control to provide a list of options that a user can select, such as a list of settings to apply to an application. Both CheckBox and RadioButton controls allow the user to select from a list of options. CheckBox controls allow the user to select a combination of options. In contrast, RadioButton controls allow the user to select from mutually exclusive options.
The CheckBox control inherits from ToggleButton and can have three states:
| State | Property | Value |
|---|---|---|
| checked | IsChecked IsChecked | true |
| unchecked | IsChecked IsChecked | false |
| indeterminate | IsChecked IsChecked | null |
For the CheckBox to report the indeterminate state, you must set the IsThreeState property to true.
Control style and template
You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a control's style and template, see Styling controls. The default style, template, and resources that define the look of the control are included in the generic.xaml file. For design purposes, generic.xaml is available in the (Program Files)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP<SDK version>\Generic folder from a Windows Software Development Kit (SDK) installation. Styles and resources from different versions of the SDK might have different values.
Starting in Windows 10, version 1607 (Windows Software Development Kit (SDK) version 10.0.14393.0), generic.xaml includes resources that you can use to modify the colors of a control in different visual states without modifying the control template. In apps that target this software development kit (SDK) or later, modifying these resources is preferred to setting properties such as Background and Foreground. For more info, see the Light-weight styling section of the Styling controls article.
This table shows the resources used by the CheckBox control.
| Resource key | Description |
|---|---|
| CheckBoxForegroundUnchecked | Label text color at rest and unchecked |
| CheckBoxForegroundUncheckedPointerOver | Label text color on hover and unchecked |
| CheckBoxForegroundUncheckedPressed | Label text color when pressed and unchecked |
| CheckBoxForegroundUncheckedDisabled | Label text color when disabled and unchecked |
| CheckBoxForegroundChecked | Label text color at rest and checked |
| CheckBoxForegroundCheckedPointerOver | Label text color on hover and checked |
| CheckBoxForegroundCheckedPressed | Label text color when pressed and checked |
| CheckBoxForegroundCheckedDisabled | Label text color when disabled and checked |
| CheckBoxForegroundIndeterminate | Label text color at rest and indeterminate |
| CheckBoxForegroundIndeterminatePointerOver | Label text color on hover and indeterminate |
| CheckBoxForegroundIndeterminatePressed | Label text color when pressed and indeterminate |
| CheckBoxForegroundIndeterminateDisabled | Label text color when disabled and indeterminate |
| CheckBoxBackgroundUnchecked | Background color of entire control at rest and unchecked |
| CheckBoxBackgroundUncheckedPointerOver | Background color of entire control on hover and unchecked |
| CheckBoxBackgroundUncheckedPressed | Background color of entire control when pressed and unchecked |
| CheckBoxBackgroundUncheckedDisabled | Background color of entire control when disabled and unchecked |
| CheckBoxBackgroundChecked | Background color of entire control at rest and checked |
| CheckBoxBackgroundCheckedPointerOver | Background color of entire control on hover and checked |
| CheckBoxBackgroundCheckedPressed | Background color of entire control when pressed and checked |
| CheckBoxBackgroundCheckedDisabled | Background color of entire control when disabled and checked |
| CheckBoxBackgroundIndeterminate | Background color of entire control at rest and indeterminate |
| CheckBoxBackgroundIndeterminatePointerOver | Background color of entire control on hover and indeterminate |
| CheckBoxBackgroundIndeterminatePressed | Background color of entire control when pressed and indeterminate |
| CheckBoxBackgroundIndeterminateDisabled | Background color of entire control when disabled and indeterminate |
| CheckBoxBorderBrushUnchecked | Border color of entire control at rest and unchecked |
| CheckBoxBorderBrushUncheckedPointerOver | Border color of entire control on hover and unchecked |
| CheckBoxBorderBrushUncheckedPressed | Border color of entire control when pressed and unchecked |
| CheckBoxBorderBrushUncheckedDisabled | Border color of entire control when disabled and unchecked |
| CheckBoxBorderBrushChecked | Border color of entire control at rest and checked |
| CheckBoxBorderBrushCheckedPointerOver | Border color of entire control on hover and checked |
| CheckBoxBorderBrushCheckedPressed | Border color of entire control when pressed and checked |
| CheckBoxBorderBrushCheckedDisabled | Border color of entire control when disabled and checked |
| CheckBoxBorderBrushIndeterminate | Border color of entire control at rest and indeterminate |
| CheckBoxBorderBrushIndeterminatePointerOver | Border color of entire control on hover and indeterminate |
| CheckBoxBorderBrushIndeterminatePressed | Border color of entire control when pressed and indeterminate |
| CheckBoxBorderBrushIndeterminateDisabled | Border color of entire control when disabled and indeterminate |
| CheckBoxCheckBackgroundStrokeUnchecked | Border color of checkmark box at rest and unchecked |
| CheckBoxCheckBackgroundStrokeUncheckedPointerOver | Border color of checkmark box on hover and unchecked |
| CheckBoxCheckBackgroundStrokeUncheckedPressed | Border color of checkmark box when pressed and unchecked |
| CheckBoxCheckBackgroundStrokeUncheckedDisabled | Border color of checkmark box when disabled and unchecked |
| CheckBoxCheckBackgroundStrokeChecked | Border color of checkmark box at rest and checked |
| CheckBoxCheckBackgroundStrokeCheckedPointerOver | Border color of checkmark box on hover and checked |
| CheckBoxCheckBackgroundStrokeCheckedPressed | Border color of checkmark box when pressed and checked |
| CheckBoxCheckBackgroundStrokeCheckedDisabled | Border color of checkmark box when disabled and checked |
| CheckBoxCheckBackgroundStrokeIndeterminate | Border color of checkmark box at rest and indeterminate |
| CheckBoxCheckBackgroundStrokeIndeterminatePointerOver | Border color of checkmark box on hover and indeterminate |
| CheckBoxCheckBackgroundStrokeIndeterminatePressed | Border color of checkmark box when pressed and indeterminate |
| CheckBoxCheckBackgroundStrokeIndeterminateDisabled | Border color of checkmark box when disabled and indeterminate |
| CheckBoxCheckBackgroundFillUnchecked | Background color of checkmark box at rest and unchecked |
| CheckBoxCheckBackgroundFillUncheckedPointerOver | Background color of checkmark box on hover and unchecked |
| CheckBoxCheckBackgroundFillUncheckedPressed | Background color of checkmark box when pressed and unchecked |
| CheckBoxCheckBackgroundFillUncheckedDisabled | Background color of checkmark box when disabled and unchecked |
| CheckBoxCheckBackgroundFillChecked | Background color of checkmark box at rest and checked |
| CheckBoxCheckBackgroundFillCheckedPointerOver | Background color of checkmark box on hover and checked |
| CheckBoxCheckBackgroundFillCheckedPressed | Background color of checkmark box when pressed and checked |
| CheckBoxCheckBackgroundFillCheckedDisabled | Background color of checkmark box when disabled and checked |
| CheckBoxCheckBackgroundFillIndeterminate | Background color of checkmark box at rest and indeterminate |
| CheckBoxCheckBackgroundFillIndeterminatePointerOver | Background color of checkmark box on hover and indeterminate |
| CheckBoxCheckBackgroundFillIndeterminatePressed | Background color of checkmark box when pressed and indeterminate |
| CheckBoxCheckBackgroundFillIndeterminateDisabled | Background color of checkmark box when disabled and indeterminate |
| CheckBoxCheckGlyphForegroundUnchecked | Check mark color at rest and unchecked |
| CheckBoxCheckGlyphForegroundUncheckedPointerOver | Check mark color on hover and unchecked |
| CheckBoxCheckGlyphForegroundUncheckedPressed | Check mark color when pressed and unchecked |
| CheckBoxCheckGlyphForegroundUncheckedDisabled | Check mark color when disabled and unchecked |
| CheckBoxCheckGlyphForegroundChecked | Check mark color at rest and checked |
| CheckBoxCheckGlyphForegroundCheckedPointerOver | Check mark color on hover and checked |
| CheckBoxCheckGlyphForegroundCheckedPressed | Check mark color when pressed and checked |
| CheckBoxCheckGlyphForegroundCheckedDisabled | Check mark color when disabled and checked |
| CheckBoxCheckGlyphForegroundIndeterminate | Check mark color at rest and indeterminate |
| CheckBoxCheckGlyphForegroundIndeterminatePointerOver | Check mark color on hover and indeterminate |
| CheckBoxCheckGlyphForegroundIndeterminatePressed | Check mark color when pressed and indeterminate |
| CheckBoxCheckGlyphForegroundIndeterminateDisabled | Check mark color when disabled and indeterminate |