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
WPF custom properties on user controls
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: WPF custom properties on user controls
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:
Regards,
Markus
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
Re: WPF custom properties on user controls
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
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: WPF custom properties on user controls
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
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
Re: WPF custom properties on user controls
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
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