将窗口的高度绑定到重量,将W绑定到H.

时间:2013-04-03 21:59:16

标签: .net wpf xaml binding

Height="{Binding Source=Self, Path=Width}"   
Width="627"   

这不起作用。首先,Height的长度为Width,但当我更改Width时,Height不想更改。

这里有什么问题?

2 个答案:

答案 0 :(得分:1)

HeightWidth定义您希望元素的大小。

在渲染视觉效果的过程中,元素的可用尺寸会根据其他所有内容进行计算,ActualHeightActualWidth会更新。

HeightWidth不会因此计算而发生变化,但如果更改HeightWidthActualHeight和{{1}重新计算。

更改您的ActualWidth路径以使用Binding,您应该最终得到一个正方形。

ActualWidth

答案 1 :(得分:1)

您应该使用RelativeSource绑定:

Height="{Binding ActualWidth,RelativeSource={RelativeSource Mode=Self}}"