Windows.UI.Xaml.Controls.Primitives.ToggleButton

July 18, 2022 · View on GitHub

-description

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.

-xaml-syntax

<ToggleButton .../>
-or-
<ToggleButton>
    singleObject
</ToggleButton>
-or-
<ToggleButton>contentString</ToggleButton>

-remarks

ToggleButton can have three states:

StatePropertyValue
checkedIsCheckedtrue
uncheckedIsCheckedfalse
indeterminateIsCheckednull

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 derived classes

ToggleButton is the parent class for several immediately derived controls that toggle and are selectable:

-examples

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]

-see-also

ButtonBase, AppBarToggleButton, CheckBox, RadioButton