-api-id | -api-type |
---|---|
T:Microsoft.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.
[!div class="nextstepaction"] Open the WinUI 3 Gallery app and see the ToggleButton in action
The WinUI 3 Gallery app includes interactive examples of most WinUI 3 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub.
The following example shows how to create a three-state ToggleButton control.
[!code-xaml1]