Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LegacyIAccessible in Windows.Automation

How to obtain LegacyIAccessible.State and others LegacyIAccessibles of AutomationElement with C# ? just like Inspect.exe from tools makes it.

like image 256
AlexGu Avatar asked Jul 26 '11 23:07

AlexGu


1 Answers

The LegacyIAccessible is new and is not available in the .NET level as is in .NET 4.0. But there is a project on CodePlex that has a newer implementation that in change set 38718 added support for this.

Be beware that you have to compile the project from source, the latest binary release is too old to contain this unfortunately...

What you want to do is something like:

if ((bool) child.GetCurrentPropertyValue(AutomationElementIdentifiers.IsLegacyIAccessiblePatternAvailableProperty)) {
    var pattern = ((LegacyIAccessiblePattern) child.GetCurrentPattern(LegacyIAccessiblePattern.Pattern));
    var state = pattern.GetIAccessible().accState;

    // Do something with state...
}

The comments in the source code says that these are new features for Windows 7, but I get it to work on Windows XP SP3...

Hope this helps!

/AZ

like image 139
Anders Zommarin Avatar answered Nov 13 '22 17:11

Anders Zommarin