LegacyIAccessible in Windows.Automation

2019-04-07 16:42发布

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

1条回答
做个烂人
2楼-- · 2019-04-07 17:11

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

查看更多
登录 后发表回答