christyjquinn
Topic Author
Posts: 17
Joined: 17 Aug 2022, 17:03

Binding dependency property to another user control isn't binding

17 Aug 2022, 17:12

Hello,

Hitting a bit of a strange issue with dependency properties and user controls.

I have a user control where a string is passed in as a dependency property:
<components:FullscreenModalComponent ImagesDir="/Images/collections_jpg" />
Inside that user control it calls another user control passing that same dependency property value down:
<components:ResponsiveImageComponent ImagesDir="{Binding ElementName=Root, Path=ImagesDir}" />
This doesn't work and just appears to do nothing. But if I bind that same property to the TextBlock control it displays that value:
<TextBlock Text="{Binding ElementName=Root, Path=ImagesDir}" />
If I assign the value directly to the nested user control it also works:
<components:ResponsiveImageComponent ImagesDir="/Images/collections_jpg" />
Any ideas/tips would be much appreciated!
 
User avatar
sfernandez
Site Admin
Posts: 3003
Joined: 22 Dec 2011, 19:20

Re: Binding dependency property to another user control isn't binding

18 Aug 2022, 20:13

Hi,

I've been able to reproduce this problem. It turns out that the binding in the inner user control is resolved against its own namescope, and because its name is also "Root", it is binding to its own property value, which is empty by default.

You can workaround the problem now by just naming each user control root differently.

Anyway, could you please report it in our bugtracker so we can fix it?
 
christyjquinn
Topic Author
Posts: 17
Joined: 17 Aug 2022, 17:03

Re: Binding dependency property to another user control isn't binding

19 Aug 2022, 12:31

Awesome thanks for the tip and great catch! Will report in the bugtracker now.
 
 
User avatar
sfernandez
Site Admin
Posts: 3003
Joined: 22 Dec 2011, 19:20

Re: Binding dependency property to another user control isn't binding

19 Aug 2022, 16:34

Thanks for the report!

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest