我有一个按钮,我想将scaleX和scaleY绑定到另一个元素的scaleX和scaleY,我该怎么做?
棘手的部分是我想将它绑定到一个元素,至少在初始化时,可能没有设置ScaleTransform ......
理想的情况下,将其设置使得bindee元素也总是有一个ScaleTransform,但它是恒等变换.然后命名为ScaleTransform,并使用通常的元素到元素语法绑定它:
<TextBlock Text="One">
<TextBlock.LayoutTransform>
<ScaleTransform ScaleX="1"
ScaleY="1"
x:Name="s" /> <!-- Note the x:Name -->
</TextBlock.LayoutTransform>
</TextBlock>
<TextBlock Text="Two">
<TextBlock.LayoutTransform>
<ScaleTransform ScaleX="{Binding ScaleX, ElementName=s}"
ScaleY="{Binding ScaleY, ElementName=s}" />
</TextBlock.LayoutTransform>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
如果需要专门绑定元素,可以遍历属性,例如{Binding LayoutTransform.ScaleX, ElementName=someElement}.如果源元素没有LayoutTransform或者它不是ScaleTransform,那么这将是no-op,但它将报告运行时绑定错误.
| 归档时间: |
|
| 查看次数: |
2431 次 |
| 最近记录: |