【发布时间】:2012-12-04 06:28:24
【问题描述】:
我正在尝试使用托管 C++ 中的 UI 自动化来查找 DataGrid 控件的 ControlType.DataItem 子项。以下 sn-p 在 C# 中对已知的 HWND 值起作用:
var automationElement = AutomationElement.FromHandle(new IntPtr(0x000602AE));
var propertyCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem);
var dataItems = automationElement.FindAll(TreeScope.Subtree, propertyCondition).Count;
Console.WriteLine("Found {0} DataItem(s)", dataItems);
这会产生以下输出:
Found 2 DataItem(s)
将代码转换为 MC++ 会产生零结果。这是转换后的 MC++ 代码:
auto automationElement = AutomationElement::FromHandle(IntPtr(0x000602AE));
auto propertyCondition = gcnew PropertyCondition(AutomationElement::ControlTypeProperty, ControlType::DataItem);
auto dataItems = automationElement->FindAll(TreeScope::Subtree, propertyCondition)->Count;
Console::WriteLine("Found {0} DataItem(s)", dataItems);
有没有其他人在使用托管 C++ 的 UI 自动化时遇到过这个问题?我过去曾将 MC++ 用于 UIA,这是我在 C# 中使用它时遇到的第一个区别。提前感谢您提供任何信息。
【问题讨论】:
标签: c# ui-automation managed-c++ uia