跳到主要内容
版本:0.10.x

CheckBox

The CheckBox control is a ContentControl which allows user to check an option. It is usually used to display a boolean option where selection is either checked or unchecked. But it also supports three state mode where selection is either checked, indeterminate or unchecked.

Common Properties

PropertyDescription
IsCheckedIs CheckBox checked
IsThreeStateIs CheckBox in three state mode

Reference

Checkbox

Source code

CheckBox.cs

Examples

Basic checkbox

<Window xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaAppTemplate.MainWindow"
Title="CheckBox sample">
<StackPanel>
<CheckBox>Not checked by default</CheckBox>
<CheckBox IsChecked="True">Checked by default</CheckBox>
</StackPanel>
</Window>

produces following output with Windows 10

Basic checkbox

Three state checkbox

<Window xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaAppTemplate.MainWindow"
Title="CheckBox sample">
<StackPanel>
<CheckBox IsThreeState="True" IsChecked="False">Not checked by default</CheckBox>
<CheckBox IsThreeState="True" IsChecked="True">Checked by default</CheckBox>
<CheckBox IsThreeState="True" IsChecked="{x:Null}">Indeterminate by default</CheckBox>
</StackPanel>
</Window>

produces following output with Windows 10

Basic checkbox