如何将 ScaleTransformation.X 绑定到 Silverlight 3 中的滑块 [英] How to bind ScaleTransformation.X to slider in Silverlight 3
问题描述
我需要缩放 Canvas.在 WPF 中,可以将 ScaleTransformation.X 绑定到 slider.Value.
I need to zoom Canvas. In WPF it is possible to bind ScaleTransformation.X to slider.Value.
我无法在 Silverlight 中做同样的事情 - 一些错误.
I'm not able to do the same in Silverlight - some errors.
SL3 支持吗?
谢谢.
推荐答案
这不起作用的原因是在 SL3 中绑定目标需要是 FrameworkElement
.(此限制已在 SL4 中解除,但目前无济于事).
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).
然而,解决方案只需要一点横向思维(或在这种情况下向后思维).源对象不需要是框架元素.所以答案是反向绑定,即将绑定放在 Slider
Value
属性上,并将其置于 TwoWay
模式.
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" />
这篇关于如何将 ScaleTransformation.X 绑定到 Silverlight 3 中的滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!