ToggleButton ToggleButton ToggleButton 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
<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

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:

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" />

Constructors

ToggleButton() ToggleButton() ToggleButton()

Initializes a new instance of the ToggleButton class.

public ToggleButton()public ToggleButton()Public Sub New()
Attributes

Properties

IsChecked IsChecked IsChecked

Gets or sets whether the ToggleButton is checked.

public IReference<bool> IsChecked { get; set; }public IReference<bool> IsChecked { get; set; }Public ReadWrite Property IsChecked As IReference<bool>
<togglebutton IsChecked="bool"/>
-or-
<togglebutton IsChecked="{x:Null}"/>
Value

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).

Attributes

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

Identifies the IsChecked dependency property.

public static DependencyProperty IsCheckedProperty { get; }public static DependencyProperty IsCheckedProperty { get; }Public Static ReadOnly Property IsCheckedProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsChecked dependency property.

Attributes

IsThreeState IsThreeState IsThreeState

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

public bool IsThreeState { get; set; }public bool IsThreeState { get; set; }Public ReadWrite Property IsThreeState As bool
<togglebutton IsThreeState="bool"/>
Value
bool bool bool

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

Attributes

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

Identifies the IsThreeState dependency property.

public static DependencyProperty IsThreeStateProperty { get; }public static DependencyProperty IsThreeStateProperty { get; }Public Static ReadOnly Property IsThreeStateProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsThreeState dependency property.

Attributes

Methods

OnToggle() OnToggle() OnToggle()

Called when the ToggleButton receives toggle stimulus.

protected virtual void OnToggle()protected virtual void OnToggle()Protected Overridable Function OnToggle() As void
Attributes

Remarks

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

Events

Checked Checked Checked

Fires when a ToggleButton is checked.

public event RoutedEventHandler Checkedpublic event RoutedEventHandler CheckedPublic Event Checked
<togglebutton Checked="eventhandler"/>
Attributes

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
<togglebutton Indeterminate="eventhandler"/>
Attributes

Unchecked Unchecked Unchecked

Occurs when a ToggleButton is unchecked.

public event RoutedEventHandler Uncheckedpublic event RoutedEventHandler UncheckedPublic Event Unchecked
<togglebutton Unchecked="eventhandler"/>
Attributes

See Also