Checkbox
The Checkbox widget displays a toggleable checked/unchecked/indeterminate state with an optional label.
Basic Usage
Create a checkbox with the Checkbox() extension method. Use OnToggled() to handle state changes.
csharp
dotnet runKey features:
- Click or press Space/Enter to toggle
- Use
Label()to add descriptive text - Manage state externally (checkboxes are stateless widgets)
States
Checkboxes support three visual states:
csharp
dotnet run| State | Display | Usage |
|---|---|---|
Unchecked | [ ] | Default, option not selected |
Checked | [x] | Option is selected |
Indeterminate | [-] | Partial selection (e.g., some children selected) |
Fluent API
| Method | Description |
|---|---|
Checked() | Set to checked state |
Unchecked() | Set to unchecked state |
Indeterminate() | Set to indeterminate state |
Label(string) | Add label text after the checkbox |
OnToggled(handler) | Handle toggle events |
Keyboard Support
| Key | Action |
|---|---|
| Space | Toggle the checkbox |
| Enter | Toggle the checkbox |
| Tab | Move to next focusable widget |
Related Widgets
- ToggleSwitch — On/off switch with visual feedback
- Tree — Hierarchical lists with multi-select checkboxes
- Button — Clickable actions