WPF custom properties on user controls

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
merklh
Posts: 24
Joined: Thu Jan 03, 2013 6:55 pm

WPF custom properties on user controls

Post by merklh » Sat Jun 08, 2013 12:46 am

Hi,

Is there a way to expose a custom property on a WPF user control and read its value through Ranorex? Ideally it should also show in Ranorex Spy but that's not absolutely necessary.

Thanks!

Hans

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: WPF custom properties on user controls

Post by Support Team » Mon Jun 10, 2013 3:49 pm

Hi,

Yes, this is possible.
You could use one of the not used attributes, for instance "ItemStatus", in order to get the value of the custom property with Ranorex.
Here is a small sample which shows how this could work in WPF. The code shows how to expose the background color attribute of a button:
<Button Background="Red" AutomationProperties.ItemStatus="{Binding RelativeSource={RelativeSource Self}, Path=Background}">
            MyButton
        </Button>
I hope this will point you in the right direction.

Regards,
Markus
.
Image

merklh
Posts: 24
Joined: Thu Jan 03, 2013 6:55 pm

Re: WPF custom properties on user controls

Post by merklh » Mon Jun 10, 2013 6:46 pm

Hi Markus,

Thanks for the suggestion. I have tested it and it works.

My only problem is that it feels a little "hacky" if you know what I mean. Is there a way to expose a property to automation so it can be accessed directly and is also visible to Ranorex Spy? I think we can live with the ItemStatus solution but I wonder if there is a more elegant/robust way.

Cheers,

Hans

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: WPF custom properties on user controls

Post by Support Team » Tue Jun 11, 2013 4:55 pm

Hi Hans,

Ranorex uses accessibility (UI Automation) for testing of WPF applications. This accessibility (UI Automation) infrastructure only exposes a subset of control properties which is limiting in some cases.
There might be other workarounds as well (for instance overwriting the IValueProvider) but the posted workaround seems to be the easiest one for me ;).

Regards,
Markus
.
Image

merklh
Posts: 24
Joined: Thu Jan 03, 2013 6:55 pm

Re: WPF custom properties on user controls

Post by merklh » Tue Jun 11, 2013 8:01 pm

Hi Markus,

I think we have what we need for now. The ItemStatus solution works and if we ever want to make things more elegant we know where to look.

Thanks!

Hans