2

我无法通过 UI 自动化框架访问我​​的 WPF UserControl DependencyProperty 值。

我以 MSDN 中的 James McCaffreys 文章作为起点(Automating IO Tests in WPF Applications,MSDN March 2009),但我只能在标准控件(如按钮)中查看属性等。

我假设我必须在我的 UserControl 上实现一些自动化接口,但是什么以及如何实现?

我已经可以很好地看到我的控件,例如在 UISpy 中,但是我看不到其中的依赖属性。这是我的用户控件当前在 UISpy 中的样子:

AutomationElement 通用辅助功能 AccessKey:“”AcceleratorKey:“”IsKeyboardFocusable:“False”LabeledBy:“(null)”HelpText:“开关48v幻象电源开/关(仅用于麦克风输入)。”

状态 IsEnabled:“True” HasKeyboardFocus:“False”

标识 ClassName:“”ControlType:“ControlType.Custom”Culture:“(null)”AutomationId:“V48SwL”LocalizedControlType:“custom”名称:“”ProcessId:“5684(VirtualSix)”RuntimeId:“7 5684 40026340”IsPassword: “假” IsControlElement:“真” IsContentElement:“真”

Visibility BoundingRectangle: "(140, 457, 31, 20)" ClickablePoint: "155,467" IsOffscreen: "False"

控制模式

4

1 回答 1

2

无法从 UI 自动化获取任意依赖属性值:您只能获取AutomationProperty值。

这个论坛帖子说,在新版本的 UIAutomation API 中,有一种方法可以添加您自己的自定义 AutomationProperties,但 WPF 尚不支持该版本的 UIA。

建议的解决方法是将您感兴趣的依赖属性绑定到 AutomationProperties.ItemStatus 附加属性:这将在 AutomationElement.Current.ItemStatus 中可用。

于 2010-03-12T12:31:12.217 回答