Page 1 of 1

Binding dependency property to another user control isn't binding

Posted: 17 Aug 2022, 17:12
by christyjquinn
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!

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

Posted: 18 Aug 2022, 20:13
by sfernandez
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?

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

Posted: 19 Aug 2022, 12:31
by christyjquinn
Awesome thanks for the tip and great catch! Will report in the bugtracker now.

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

Posted: 19 Aug 2022, 12:47
by christyjquinn

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

Posted: 19 Aug 2022, 16:34
by sfernandez
Thanks for the report!