How to bind ScaleTransformation.X to slider in Silverlight 3

风流意气都作罢 提交于 2019-12-11 11:47:49

问题


I need to zoom Canvas. In WPF it is possible to bind ScaleTransformation.X to slider.Value.

I'm not able to do the same in Silverlight - some errors.

Is it supported in SL3?

Thank you.


回答1:


The reason this doesn't work is that in SL3 the binding target needs to be a FrameworkElement. (This restriction is lifted in SL4 but that doesn't help right now).

However the solution just takes a little lateral thinking (or in this case backward thinking). The source object does not need to be a Framework element. So the answer is reverse the binding, that is put the binding on the Slider Value property and put it in to TwoWay mode.

<Border Width="200" Height="200">
    <Border.RenderTransform>
        <ScaleTransform x:Name="TargetTransform" />
    </Border.RenderTransform>
    <!-- Some Content Here -->
</Border>

<Slider Value="{Binding ScaleX, ElementName=TargetTransform, Mode=TwoWay}"
    Width="200" Canvas.Top="250" 
    Minimum="0.1" Maximum="2.0" />


来源:https://stackoverflow.com/questions/1850380/how-to-bind-scaletransformation-x-to-slider-in-silverlight-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!