.NET Framework Class Library for Silverlight
ToggleButton Class

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

Namespace:  System.Windows.Controls.Primitives
Assembly:  System.Windows (in System.Windows.dll)
Syntax

Visual Basic (Declaration)
<TemplateVisualStateAttribute(Name := "Normal", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Unchecked", GroupName := "CheckStates")> _
<TemplateVisualStateAttribute(Name := "Indeterminate", GroupName := "CheckStates")> _
<TemplateVisualStateAttribute(Name := "MouseOver", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Pressed", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Disabled", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Unfocused", GroupName := "FocusStates")> _
<TemplateVisualStateAttribute(Name := "Focused", GroupName := "FocusStates")> _
<TemplateVisualStateAttribute(Name := "Checked", GroupName := "CheckStates")> _
Public Class ToggleButton _
    Inherits ButtonBase
Visual Basic (Usage)
Dim instance As ToggleButton
C#
[TemplateVisualStateAttribute(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Unchecked", GroupName = "CheckStates")]
[TemplateVisualStateAttribute(Name = "Indeterminate", GroupName = "CheckStates")]
[TemplateVisualStateAttribute(Name = "MouseOver", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Pressed", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Disabled", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Unfocused", GroupName = "FocusStates")]
[TemplateVisualStateAttribute(Name = "Focused", GroupName = "FocusStates")]
[TemplateVisualStateAttribute(Name = "Checked", GroupName = "CheckStates")]
public class ToggleButton : ButtonBase
XAML Object Element Usage
<ToggleButton .../>
-or-
<togglebutton>
  singleObject
</togglebutton>

XAML Values

singleObject

A single object element that declares the content.

togglebutton

A ToggleButton object element or an object element for a class that derives from ToggleButton.

Remarks

The IsChecked property specifies the state of the ToggleButton. The IsThreeState property specifies whether the ToggleButton has two or three states. If the ToggleButton is configured to have three states, it allows the user to choose a third, indeterminate state. For example, you could use a three-state toggle button to indicate Yes, No, or Not Applicable.

Content Model:  ToggleButton is a ContentControl. Its content property is Content. For more information, see Control Content Models.

Examples

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

Run this sample

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

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.UIElement
      System.Windows..::.FrameworkElement
        System.Windows.Controls..::.Control
          System.Windows.Controls..::.ContentControl
            System.Windows.Controls.Primitives..::.ButtonBase
              System.Windows.Controls.Primitives..::.ToggleButton
                System.Windows.Controls..::.CheckBox
                System.Windows.Controls..::.RadioButton
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Other Resources

Tags :


Page view tracker