1

基本上我正在使用 UIAutomationClient.Interop.dll 进行我目前正在做的一些 UI 工作,我面临以下问题:

  • 我有一个 UI 元素,我想知道它的控件类型。
  • UIAutomationClient.Interop.dll公开以下属性:IUIAutomationElement::CurrentControlType 属性
  • 上面的属性返回一个表示控件类型 ID 但不是控件类型对象的 Int。

问题:

  • 只知道它的 ID,我怎么能知道 UI 元素的 ControlType 是什么?我无法找到任何其他有用的信息。

注意

我正在使用 UIAutomationTypes.dll 来定义 ControlType 对象

任何想法?

4

2 回答 2

1

GetCurrentPropertyValue(AutomationElement.ControlTypeProperty)在 IronPython 中使用。可能这就是你想要的。它应该返回 ControlType 对象。虽然我使用它的字符串表示.ProgrammaticName.lstrip('ControlType.').strip("'")

于 2014-07-15T08:33:26.263 回答
0

对于那些仍在寻找如何在 2021 年做到这一点的人(使用 IUIAutomationElement)。您只需使用LookupById()System.Windows.Automation.ControlType 类提供的功能。

// 
IUIAutomationElement element;
// ...
// your code to retrieve the element you want
// ...

// the next line fixes a bug in ControlType class, as explained here: https://stackoverflow.com/a/13971182/991782
ControlType.Button.ToString();

var elementControlType = System.Windows.Automation.ControlType.LookupById(element.CurrentControlType);
于 2021-03-31T16:09:24.527 回答