Toggle Method
Collapse the table of content
Expand the table of content

IToggleProvider.Toggle Method ()


Cycles through the toggle states of a control.

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

void Toggle()

A control must cycle through its toggle states in this order: On, Off, and (if supported) Indeterminate.

The following example shows one possible implementation of this method for a custom control that can be toggled.

/// <summary>
/// Toggles the control.
/// </summary>
/// <remarks>
/// For this custom control the toggle state is reflected by the color 
/// of the control. This is analogous to the CheckBox IsChecked property.
/// Green   - ToggleState.On
/// Red     - ToggleState.Off
/// Yellow  - ToggleState.Indeterminate
/// </remarks>
void IToggleProvider.Toggle()
    ToggleState toggleState = 
    // Invoke control method on separate thread to avoid clashing with UI.
    // Use anonymous method for simplicity.
    this.customControl.Invoke(new MethodInvoker(delegate()
        if (toggleState == ToggleState.On)
            customControl.controlColor = Color.Red;
        else if (toggleState == ToggleState.Off)
            customControl.controlColor = Color.Yellow;
        else if (toggleState == ToggleState.Indeterminate)
            customControl.controlColor = Color.Green;

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2016 Microsoft