开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜