TogglePattern.TogglePatternInformation.ToggleState Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Retrieves the toggle state of the AutomationElement.

Namespace:   System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public ToggleState ToggleState { get; }

Property Value

Type: System.Windows.Automation.ToggleState

The ToggleState of the AutomationElement. The default value is Indeterminate.

An AutomationElement must cycle through its ToggleState in this order: On, Off and, if supported, Indeterminate.

In the following example, a root element is passed to a function that returns a collection of automation elements that are descendants of the root and satisfy a set of property conditions.

/// <summary>
/// Finds all automation elements that satisfy 
/// the specified condition(s).
/// </summary>
/// <param name="rootElement">
/// The automation element from which to start searching.
/// </param>
/// <returns>
/// A collection of automation elements satisfying 
/// the specified condition(s).
/// </returns>
private AutomationElementCollection FindAutomationElement(
    AutomationElement rootElement)
    if (rootElement == null)
        throw new ArgumentException("Root element cannot be null.");

    PropertyCondition conditionOn =
        new PropertyCondition(
        TogglePattern.ToggleStateProperty, ToggleState.On);

    PropertyCondition conditionIndeterminate =
        new PropertyCondition(
        TogglePattern.ToggleStateProperty, ToggleState.Indeterminate);

    // Use any combination of the preceding condtions to 
    // find the control(s) of interest
    OrCondition condition = new OrCondition(

    return rootElement.FindAll(TreeScope.Descendants, condition);

.NET Framework
Available since 3.0
Return to top