I have the following structure:
Window1 -> UserControlA -> UserControlB -> UserControlC
Each has its own view model. How can I create a property on UserControlA that depends on a property of UserControlC?
The only thing I can think of is to expose C’s property changed event from B so I can listen for the C’s events from A and update A’s dependency property. The problem is that this seems WAY too contrived so I think there has to be a simpler solution.
You can chain the
Dependency Propertiesto achieve this. You need to expose dp in all your user controls. Bind the property ofUserControlCwithUserControlBand thenUserControlA. This way whenever property inUserControlCis changed, property inUserControlAis also changed.A.xaml.cs
B.xaml.cs
C.xaml.cs
A.xaml
B.xaml
Whenever Text of C is changed, binding updates the value of TextA. And definitely you have to map the dp with their corresponding viewmodel properties in their control template.