WPF How To Bind Two Nested Usercontrols
I need to bind a user control data context with ot开发者_如何学JAVAher control property :
<StackPanel>
<custom:UserControl1 x:Name="UC1"/>
</StackPanel>
<StackPanel>
<custom:UserControl2 DataContext="{Binding ElementName=UC1, Path=MySelectedValue}"/>
</StackPanel>
Of course i have implemented a dependency property 'MySelectedValue' on UserControl1. The following does not work. I guess because it searches the ElementName on the visual tree and could not find it because both controls are parallel nested.
How could i get the above to work?
Thanks,
How did you define the MySelectedValue DependencyProperty (is it set to BindsTwoWayByDefault)?
Vlad had solved this for me mentioning that everything is actually fine! I had my dependency property not defined properly.
It seems that the 'ElementName' binding works even if the element is nested on parallel with the calling element.
Thank you.
精彩评论