LegacyIAccessible in Windows.Automation

試著忘記壹切 提交于 2020-01-01 09:37:11

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/6837935/legacyiaccessible-in-windows-automation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!