Question

I'm having trouble getting access to my WPF UserControl DependencyProperty values through the UI Automation Framework.

I've used James McCaffreys article in MSDN as a starting point (Automating IO Tests in WPF Applications, MSDN March 2009), but I can only see properties etc in standard controls such as buttons.

I'm assuming there's some Automation interface I have to implement on my UserControl, but what and how?

I can already see my control fine e.g. in UISpy, but I can't see the dependency properties within it. Here's what my usercontrol looks like currently in UISpy:

AutomationElement General Accessibility AccessKey: "" AcceleratorKey: "" IsKeyboardFocusable: "False" LabeledBy: "(null)" HelpText: "Switches 48v Phantom Power On/Off (for Mic inputs only)."

State IsEnabled: "True" HasKeyboardFocus: "False"

Identification ClassName: "" ControlType: "ControlType.Custom" Culture: "(null)" AutomationId: "V48SwL" LocalizedControlType: "custom" Name: "" ProcessId: "5684 (VirtualSix)" RuntimeId: "7 5684 40026340" IsPassword: "False" IsControlElement: "True" IsContentElement: "True"

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

ControlPatterns

Was it helpful?

Solution

There's no way of getting arbitrary Dependency Property values from UI Automation: you can only get AutomationProperty values.

This forum post says that in the new version of the UIAutomation API there is a way of adding your own custom AutomationProperties, but that version of UIA isn't supported by WPF yet.

A suggested workaround is to bind the Dependency Property your are interested in to the AutomationProperties.ItemStatus attached property: this will then be available in AutomationElement.Current.ItemStatus.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top