WPF support of System.Windows.Shapes available?

Ask general questions here.
vtp
Posts: 7
Joined: Wed Sep 16, 2009 4:39 pm

WPF support of System.Windows.Shapes available?

Post by vtp » Thu Oct 15, 2009 2:53 pm

Hello!

When I try to test a WPF application I can get Informations about the Image but no informations about also available "Ellipse" elements. So I tried to test with a very small WPF application with a WPF ellipse (and a WPF button). Again I get no information about the ellipse (but had no problem with the button).

So why get I no information about the ellipse (System.Windows.Shapes.Ellipse) which is in the inheritance hierarchy under FrameworkElement (System.Windows.FrameworkElement) and get information about the image (System.Windows.Controls.Image) which also is in the inheritance hierarchy under FrameworkElement (System.Windows.FrameworkElement)?

Can you please tell what I must do that the spy (or the recorder) knows these WPF shapes (ellipse, line, ...) - or if these elements are not supported do you know when it is planned to do so?

Thank you very much.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: WPF support of System.Windows.Shapes available?

Post by Support Team » Fri Oct 16, 2009 9:00 am

Ranorex internally uses UIAutomation to interact with Silverlight/WPF applications. Shapes are not shown, because by default Shapes do not provide an UIAutomation interface (since they do not support user interaction). For Shapes to show up in the Ranorex element tree, you need to override the UIElement.OnCreateAutomationPeer method and return an AutomationPeer class.

Below is sample code that creates a custom Canvas control that overrides the OnCreateAutomationPeer method and is thus shown by Ranorex (I did that sample once for a customer, I'm pretty sure, you can adapt the sample for Shapes). I.e. if you want your Shapes to show up in Ranorex, (in your Silverlight/WPF application) replace the default Shapes with custom ones that inherit from the orignal Shapes and that override the OnCreateAutomationPeer method:
public class RanorexVisibleCanvas : Canvas
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new FrameworkElementAutomationPeer(this);
    }
}
In your XAML file use this custom class instead of the default Canvas class:
<Window ... xmlns:src="clr-namespace:YourApplicationNameSpace" ...>
...
<src:RanorexVisibleCanvas x:Name="myRanorexVisibleCanvas"> 
    <Button>Click me!</Button>
</src:RanorexVisibleCanvas>
...
</Window>
Regards,
Alex
Ranorex Support Team