Toggle​Button Toggle​Button Toggle​Button Toggle​Button Class

Definition

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.

public : class ToggleButton : ButtonBase, IToggleButton, IToggleButtonOverridespublic class ToggleButton : ButtonBase, IToggleButton, IToggleButtonOverridesPublic Class ToggleButton Inherits ButtonBase Implements IToggleButton, IToggleButtonOverrides// This API is not available in Javascript.
<ToggleButton .../>
-or-
<ToggleButton>
    singleObject
</ToggleButton>
-or-
<ToggleButton>contentString</ToggleButton>
Inheritance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Inherited Members

Inherited properties

Inherited events

Inherited methods

Examples

The following example shows how to create a three-state ToggleButton control.

<ToggleButton Margin="5" Content="Three State" Width="150" IsThreeState="True"/>
<ToggleButton Margin="5" Content="Two State" Width="150" IsThreeState="False" />

Remarks

ToggleButton and can have three states:

StatePropertyValue
checkedIsChecked IsChecked true
uncheckedIsChecked IsChecked false
indeterminateIsChecked 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 derived classes

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

Constructors

ToggleButton() ToggleButton() ToggleButton() ToggleButton()

Initializes a new instance of the ToggleButton class.

public : ToggleButton()public ToggleButton()Public Sub New()// This API is not available in Javascript.

Properties

IsChecked IsChecked IsChecked IsChecked

Gets or sets whether the ToggleButton is checked.

public : IReference<bool> IsChecked { get; set; }public Nullable<bool> IsChecked { get; set; }Public ReadWrite Property IsChecked As Nullable<bool>// This API is not available in Javascript.
<togglebutton IsChecked="bool"/>
-or-
<togglebutton IsChecked="{x:Null}"/>
Value
IReference<PlatForm::Boolean> Nullable<bool> Nullable<bool> Nullable<bool>

true if the ToggleButton is checked; false if the ToggleButton is unchecked; otherwise null. The default is false.

If you are programming using C#or Microsoft Visual Basic, the type of this property is projected as bool?(a nullable Boolean).

Remarks

ToggleButton and can have three states:

StatePropertyValue
checkedIsChecked IsChecked true
uncheckedIsChecked IsChecked false
indeterminateIsChecked 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.

To set the value to null in XAML, use the {x:Null} markup extension.

See Also

IsCheckedProperty IsCheckedProperty IsCheckedProperty IsCheckedProperty

Identifies the IsChecked dependency property.

public : static DependencyProperty IsCheckedProperty { get; }public static DependencyProperty IsCheckedProperty { get; }Public Static ReadOnly Property IsCheckedProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsChecked dependency property.

IsThreeState IsThreeState IsThreeState IsThreeState

Gets or sets a value that indicates whether the control supports three states.

public : PlatForm::Boolean IsThreeState { get; set; }public bool IsThreeState { get; set; }Public ReadWrite Property IsThreeState As bool// This API is not available in Javascript.
<togglebutton IsThreeState="bool"/>
Value
PlatForm::Boolean bool bool bool

True if the control supports three states; otherwise, false. The default is false.

Remarks

ToggleButton and can have three states:

StatePropertyValue
checkedIsChecked IsChecked true
uncheckedIsChecked IsChecked false
indeterminateIsChecked 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.

IsThreeStateProperty IsThreeStateProperty IsThreeStateProperty IsThreeStateProperty

Identifies the IsThreeState dependency property.

public : static DependencyProperty IsThreeStateProperty { get; }public static DependencyProperty IsThreeStateProperty { get; }Public Static ReadOnly Property IsThreeStateProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsThreeState dependency property.

Methods

OnToggle() OnToggle() OnToggle() OnToggle()

Called when the ToggleButton receives toggle stimulus.

protected : virtual void OnToggle()protected virtual void OnToggle()Protected Overridable Function OnToggle() As void// This API is not available in Javascript.

Remarks

The default implementation raises a Click event in response to the stimulus.

Events

Checked Checked Checked Checked

Fires when a ToggleButton is checked.

public : event RoutedEventHandler Checkedpublic event RoutedEventHandler CheckedPublic Event Checked// This API is not available in Javascript.
<togglebutton Checked="eventhandler"/>

Indeterminate Indeterminate Indeterminate Indeterminate

Fires when the state of a ToggleButton is switched to the indeterminate state.

public : event RoutedEventHandler Indeterminatepublic event RoutedEventHandler IndeterminatePublic Event Indeterminate// This API is not available in Javascript.
<togglebutton Indeterminate="eventhandler"/>

Unchecked Unchecked Unchecked Unchecked

Occurs when a ToggleButton is unchecked.

public : event RoutedEventHandler Uncheckedpublic event RoutedEventHandler UncheckedPublic Event Unchecked// This API is not available in Javascript.
<togglebutton Unchecked="eventhandler"/>

See Also