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

Syntax

Declaration

public class ToggleButtonpublic class ToggleButtonPublic Class ToggleButton
<ToggleButton .../>
-or-
<ToggleButton>
    singleObject
</ToggleButton>
-or-
<ToggleButton>contentString</ToggleButton>

Inheritance Hierarchy

Inherited Members

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Tag
Tag
Tag
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Remarks

ToggleButton and can have three states:

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

Initializes a new instance of the ToggleButton class.

Properties summary

Gets or sets whether the ToggleButton is checked.

Identifies the IsChecked dependency property.

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

Identifies the IsThreeState dependency property.

Methods summary

Called when the ToggleButton receives toggle stimulus.

Events summary

Fires when a ToggleButton is checked.

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

Occurs when a ToggleButton is unchecked.

Constructors

  • ToggleButton()
    ToggleButton()
    ToggleButton()
    ToggleButton()

    Initializes a new instance of the ToggleButton class.

    public ToggleButton()public ToggleButton()Public Function ToggleButton() As

Properties

  • IsChecked
    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}"/>
    

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

    Remarks

    ToggleButton and can have three states:

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

  • 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

    Property Value

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

    Property Value

    • 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 true
    uncheckedIsChecked false
    indeterminateIsChecked 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

    Property Value

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

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

    Occurs when a ToggleButton is unchecked.

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.UI.Xaml.Controls.Primitives.dll