ToggleButton Class

Definition

Base class for controls that can switch states, such as CheckBox.

public class ToggleButton : System.Windows.Controls.Primitives.ButtonBase
Inheritance
Derived
System.Windows.Controls.CheckBox
System.Windows.Controls.RadioButton
System.Windows.Controls.Ribbon.RibbonToggleButton

Inherited Members

System.Object

System.Windows.Controls.ContentControl

System.Windows.Controls.Control

System.Windows.Controls.Primitives.ButtonBase

System.Windows.DependencyObject

System.Windows.FrameworkElement

System.Windows.Media.Visual

System.Windows.Threading.DispatcherObject

System.Windows.UIElement

Remarks

A ToggleButton is a ContentControl, which means that it can contain a single object of any type (such as a string, an image, or a panel). For more information, see the ContentControl class.

The IsChecked property specifies the state of the ToggleButton. The IsThreeState property specifies whether the ToggleButton has two or three states.

Customizing the ToggleButton Control

To apply the same property settings to multiple ToggleButton controls, use the Style property. You can modify the default ControlTemplate to give the control a unique appearance. For more information about creating a ControlTemplate, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. To see the parts and states that are specific to the ToggleButton, see ToggleButton Syles and Templates.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Default WPF Themes.

Note

Setting a visual property will only have an effect if that property is both present in Button control's default template and is set by using a . You can find a list of visual properties in the "Changing the Visual Structure of a Control" section in Customizing the Appearance of an Existing Control by Creating a ControlTemplate.

Constructors

ToggleButton()

Initializes a new instance of the ToggleButton class.

Fields

CheckedEvent

Identifies the Checked routed event.

IndeterminateEvent

Identifies the Indeterminate routed event.

IsCheckedProperty

Identifies the IsChecked dependency property.

IsThreeStateProperty

Identifies the IsThreeState dependency property.

UncheckedEvent

Identifies the Unchecked routed event.

Properties

IsChecked

Gets or sets whether the ToggleButton is checked.

IsThreeState

Determines whether the control supports two or three states.

Methods

OnChecked(RoutedEventArgs)

Called when a ToggleButton raises a Checked event.

OnClick()

Called when a control is clicked by the mouse or the keyboard.

OnCreateAutomationPeer()

Provides an appropriate ToggleButtonAutomationPeer implementation for this control, as part of the WPF infrastructure.

OnIndeterminate(RoutedEventArgs)

Called when a ToggleButton raises an Indeterminate event.

OnToggle()

Called by the OnClick() method to implement toggle behavior.

OnUnchecked(RoutedEventArgs)

Called when a ToggleButton raises an Unchecked event.

ToString()

Returns the string representation of a ToggleButton object.

Events

Checked

Occurs when a ToggleButton is checked.

Indeterminate

Occurs when the state of a ToggleButton is neither on nor off.

Unchecked

Occurs when a ToggleButton is unchecked.