Problem accessing patterns.

Nov 10, 2011 at 6:30 PM


I am not sure if this is an issue related with the wrapper or the COM API but after switching to using this wrapper from the initial manged libary code, I lost of a lot of reported patterns. In particular an element which used to return a ValuePattern no longer does so. I have also checked using the UI Spy and the UI Spy shows that the element does indeed support the ValuePattern. 

Nov 11, 2011 at 4:28 PM

I found the issue, for those who run into the same problem - even if GetSupportedPatterns doesn't return anything, you want to look for the LegacyIAccessiblePattern, it might contain the value you need. Use the inspector tool which comes with the Windows SDK and check to see which patterns are supported. (Don't fully trust the GetSupportedPatterns function)

Feb 22, 2012 at 10:10 AM


Could you please post a code sample of how you use that LegacyIAccessiblePattern?I'm desperately trying to retreive it, but I have the following issue:

If I use this code:

AutomationElement element = AutomationElement.FocusedElement;

int patternId = UIAutomationClient.UIA_PatternIds.UIA_LegacyIAccessiblePatternId;

IUIAutomationLegacyIAccessiblePattern legacyPattern = (IUIAutomationLegacyIAccessiblePattern)element.GetCurrentPattern(patternId);

->This last statement returns an error since the GetCurrentPattern method only accepts AutomationPattern argument. (which makes sense since my element is an AutomationElement...)

Thanks in advance.

Apr 2, 2012 at 6:36 AM

In the last statement, use LegacyIAccessiblePattern.Pattern instead -- LegacyIAccessiblePattern is the wrapper I wrote for the IUIAutomationLegacyIAccessiblePattern COM interface.



May 4, 2012 at 11:44 AM

Hello Michael,

returning to the topic: your wrapper (I used the Windows 8 CP version) has lost old good SelectionItem and ExpandCollapse patterns.

Yesterday, I switched my powershell wrapper to your wrapper and faced two issues:

1. being built on Windows 8 CP, it significantly slower than built on Windows 7 and much more slower than the original version (I have unit tests with time for getting a control no more than two seconds on an almost empty form. The 'Windows 8' build failed many of these tests, and the 'Windows 7' build failed several. The 'native' build never failed).

2. Some aptterns are inaccessible.

The first issue is worth opening a new thread, so that what I have for you to help investigating into the second issue:

I posted an archive ( ) that includes two projects: the 'native' (witn out-of-the-box UIAutomaitonClient, called UIAutomation.Old_last_MS) and with 'Windows 8 CP' wrapper (its folder called UIAutomation.Old).

Both projects have compiled binaries.

Also, there is a script runToCheck.ps1 and a project with a simple form.

You may do the following:

1. run the application under test (testcombo)

2. edit the script (change the path in the ipmo statement to set to the path to UIAutomation.Old_last_MS project and uncomment the statement)

3. run powershell as administrator and run the script, observe results

4. edit the script to set the path to UIAutomation.Old

5. run powershell as administrator and the script in it

6. watch that this time it does less

The 'original' version returns ExpandCollapse, for example. The verison with your wrapper returns ValuePattern and some new pattern only.


Could you please fix the issue with 'less patterns'? After the fix, I'd like to work closely on the performance issue to benefit from the new patterns you expose in the wrapper..

May 9, 2012 at 7:32 PM
Edited May 9, 2012 at 7:33 PM

This issue is not caused by the wrapper, and it cannot be fixed in the wrapper.

The underlying accessibility data for the WinForms combo box control doesn't support ExpandCollapse.  If you use the Inspect SDK tool, available in the Windows 7 or Windows 8 platform SDK, you can see this.   Here's a partial dump from Inspect:


How found: Navigating to Parent...

Name: ""

ControlType: UIA_ComboBoxControlTypeId (0xC353)

LocalizedControlType: "combo box"

BoundingRectangle: {l:135 t:165 r:355 b:186}

IsEnabled: true

IsOffscreen: false

IsKeyboardFocusable: true

HasKeyboardFocus: false

AccessKey: ""

ProcessId: 14332

RuntimeId: [2A.C2204]

AutomationId: "comboBox1"

FrameworkId: "WinForm"

ClassName: ""

NativeWindowHandle: 0xC2204

ProviderDescription: "[pid:8324,hwnd:0xC2204 Main:Nested [pid:14332,hwnd:0xC2204 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]"

IsPassword: false

HelpText: ""

LegacyIAccessible.ChildId: 0

LegacyIAccessible.DefaultAction: ""

LegacyIAccessible.Description: ""

LegacyIAccessible.Help: ""

LegacyIAccessible.KeyboardShortcut: ""

LegacyIAccessible.Name: ""

LegacyIAccessible.Role: combo box (0x2E)

LegacyIAccessible.State: collapsed,focusable (0x100400)

LegacyIAccessible.Value: ""

Value.IsReadOnly: false

Value.Value: ""

IsAnnotationPatternAvailable: false

IsDragPatternAvailable: false

IsDockPatternAvailable: false

IsDropTargetPatternAvailable: false

IsExpandCollapsePatternAvailable: false

IsGridItemPatternAvailable: false

IsGridPatternAvailable: false

IsInvokePatternAvailable: false

IsItemContainerPatternAvailable: false

IsLegacyIAccessiblePatternAvailable: true

IsMultipleViewPatternAvailable: false

IsObjectModelPatternAvailable: false

IsRangeValuePatternAvailable: false

IsScrollItemPatternAvailable: false

IsScrollPatternAvailable: false

IsSelectionItemPatternAvailable: false

IsSelectionPatternAvailable: false

IsSpreadsheetItemPatternAvailable: false

IsSpreadsheetPatternAvailable: false

IsStylesPatternAvailable: false

IsSynchronizedInputPatternAvailable: false

IsTableItemPatternAvailable: false

IsTablePatternAvailable: false

IsTextChildPatternAvailable: false

IsTextPatternAvailable: false

IsTextPattern2Available: false

IsTogglePatternAvailable: false

IsTransformPatternAvailable: false

IsTransform2PatternAvailable: false

IsValuePatternAvailable: true

IsVirtualizedItemPatternAvailable: false

IsWindowPatternAvailable: false 

Since this CodePlex project simply wraps the underlying UIA COM interface, it can't create patterns that aren't available through the underlying COM API.  In this case, Inspect is showing that the WinForms combo box doesn't expose the ExpandCollapse pattern.

The next question would be, "OK, but why doesn't the COM API expose that pattern for that control?"  The managed client API for UI Automation had a number of workarounds, some of them unstable, to try to cope with WinForms and Win32 common controls.  (Another example: the client API tries to show the children of a combo box when the combo box is collapsed, but since the owner of the combo box can change the children dynamically when the combo box is opened, this collapsed children list is often inaccurate.)  The COM API for UIA doesn't reproduce most of these workarounds.

For the purpose of this CodePlex project, the results from using UiaComWrapper should be identical to the results from using the COM API from native code.  Which, in this case, they are.  If you have questions about the COM API itself, you might want to ask them in the UIA forum on MSDN.  (