3

I have a custom WPF control based on ContentControl. The control displays power grid, and does its own drawing. I'd like to have elements of power grid available through automation framework. The tricky part is that the control itself has multiple ways to draw power grid. It can draw it using WPF, or it can draw it using DirectX. When it's using DirectX (preferred mode), the control hosts WindowsFormsHost and randers on its HWND.

Now I have implemented Automation Peer on my Custom control, and elements all show nicely in Inspect (very cool). But the problem comes when trying to simulate a click through automation framework. AutomationElement.FromPoint always returns the windowsformshost automation element instead of my custom automation element.

When I look at Automation Tree it looks like this:

Window
   pane   <- Windows forms host
      pane
   Titlebar
   Custom Control <- My Custom control that displays power grid
       Power grid elements

I suppose the issue is that pane comes before my custom control, and automation framework belives that it is covering my elements. How do I work around this? Can I somehow tell Windows Forms Host not to add itself to automation tree? Or to be below my custom control?

Ivan
  • 1,735
  • 1
  • 17
  • 26
  • The pane comes before your custom control because it contains it and the tree exposes this logical structure. FromPoint method documentation states that it always returns the element that is closest to the RootElement which in this case is the containing pane. I don't know that you can hide it from the tree, but you could probably implement the Invoke pattern for your custom control your self. See here: https://msdn.microsoft.com/en-us/library/ms753352(v=vs.110).aspx – o_weisman Sep 06 '15 at 11:32

0 Answers0