CheckBox
Introduction
The CheckBox control provides the ability to display a true/false state and allows the user to toggle the state through clicking.
Code Example: Adding a CheckBox
var checkBox = new CheckBox();
stackPanel.Children.Add(checkBox.Visual);
checkBox.X = 50;
checkBox.Y = 50;
checkBox.Text = "Checkbox";
checkBox.Checked += (_,_) => Debug.WriteLine($"IsChecked:{checkBox.IsChecked}");
checkBox.Unchecked += (_, _) => Debug.WriteLine($"IsChecked:{checkBox.IsChecked}");

CheckBox Width and Height
Default CheckBoxes have the following default values:
Variable
Value
Width
128
WidthUnits
Absolute
Height
32
HeightUnits
Absolute
The text within the CheckBox draws and wraps according to the bounds of the CheckBox. In other words, longer text results in line wrapping, as show in the following code block:
var checkBox = new CheckBox();
checkBox.Text = "This is some longer text";
stackPanel.AddChild(checkBox);

Last updated
Was this helpful?