This project is read-only.


Jan 13, 2010 at 3:51 PM


there is an older closed work item which should expose Toggle on UIItem's

but I can't find a function or Property for that?

How can I find out the toggle state without using TogglePattern on different UIItems?



Jan 17, 2010 at 2:14 PM

checkbox exposes using State property, which control you are using?

Jan 18, 2010 at 7:07 AM

There are two or more elements in our application


ControlType.Button (is a toggleButton)

ControlType.MenuItem (if toggled you can see a heel in the ContextMenu)


I write a little helper function:

/// <summary>
/// Determines whether [is UI item toggled] [the specified item].
/// </summary>
/// <param name="item">The item.</param>
/// <returns>
/// 	<c>true</c> if [is UI item toggled] [the specified item]; otherwise, <c>false</c>.
/// </returns>
public static bool IsUIItemToggled(UIItem item)
    TogglePattern togglePattern = AutomationElementHelper.GetToggleAutomationElement(item.AutomationElement);
    // Return the toggle state
    ToggleState buttonState = togglePattern.Current.ToggleState;

    return ( ToggleState.On == buttonState ) ? true : false;
/// <summary>
/// Get the TogglePatern from automation element 
/// </summary>
/// <param name="element">The element</param>
/// <returns></returns>
public static TogglePattern GetToggleAutomationElement(AutomationElement element)
    TogglePattern togglePattern = null;
    AutomationPattern automationPatternFromElement = GetSpecifiedPattern( element, "TogglePatternIdentifiers.Pattern" );
    if (automationPatternFromElement != null)
       togglePattern = (TogglePattern)element.GetCurrentPattern(automationPatternFromElement);
     Assert.Fail("The AutomationElement does not support this pattern");
    return togglePattern;

Jan 18, 2010 at 10:24 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.