绑定到子对象

时间:2013-02-18 17:11:39

标签: windows-phone-7 xaml data-binding nested

我有以下代码(wp7-silverlight)。我尝试将滑块绑定到这两个控件的Angle属性,但由于某种原因,内部控件似乎没有接收数据,只有父控件。当我把它们并排放置(而不是嵌套)时,它们正常工作。知道为什么只有外部控件可以从滑块获取数据吗?

 <rotate:RotatableUserControl Width="400"
                                         Height="400"
                                         x:Name="RotatableUserControl"
                                         Angle="{Binding ElementName=SliderObject, Path=Value}">

                <Canvas Background="Red">
                    <rotate:RotatableUserControl Width="50"
                                                 Height="50"
                                                 x:Name="childeRotate3"
                                                 Angle="{Binding ElementName=SliderObject, Path=Value}">
                        <Grid Background="Yellow" />
                    </rotate:RotatableUserControl>
                </Canvas>
            </rotate:RotatableUserControl>

1 个答案:

答案 0 :(得分:0)

我不确定为什么你不能嵌套绑定它,但你可以尝试将画布Datacontext设置为SliderObject并将Value绑定到嵌套的rotate:RotatableUserControl,这可能有效!

 <rotate:RotatableUserControl Width="400"
                                     Height="400"
                                     x:Name="RotatableUserControl"
                                     Angle="{Binding ElementName=SliderObject, Path=Value}">

            <Canvas Background="Red" Datacontext={Binding ElementName=SliderObject, Path=Value}">
                <rotate:RotatableUserControl Width="50"
                                             Height="50"
                                             x:Name="childeRotate3"
                                             Angle="{Binding}">
                    <Grid Background="Yellow" />
                </rotate:RotatableUserControl>
            </Canvas>
        </rotate:RotatableUserControl>