-api-id | -api-type |
---|---|
T:Windows.UI.Xaml.Controls.Primitives.ToggleButton |
winrt class |
Represents a control that a user can select (check) or clear (uncheck). Base class for controls that can switch states, such as CheckBox and RadioButton.
<ToggleButton .../>
-or-
<ToggleButton>
singleObject
</ToggleButton>
-or-
<ToggleButton>contentString</ToggleButton>
ToggleButton can have three states:
State | Property | Value |
---|---|---|
checked | IsChecked | true |
unchecked | IsChecked | false |
indeterminate | IsChecked | null |
For the ToggleButton to report the indeterminate state, you must set the IsThreeState property to true.
Note
ToggleButton has the same visual state for the indeterminate and unchecked states. Derived controls, like CheckBox, may define different visual states for each state.
ToggleButton is the parent class for several immediately derived controls that toggle and are selectable:
Tip
For more info, design guidance, and code examples, see Toggle switches.
If you have the WinUI 2 Gallery app installed, click here to open the app and see the ToggleButton in action.
The following example shows how to create a three-state ToggleButton control.
[!code-xaml1]