【发布时间】:2019-04-24 21:56:35
【问题描述】:
例如,如果我想画一个正方形,每边 50 px,代码如下:<Rectangle Width="50" Height="{Binding Path=Width,RelativeSource={RelativeSource Self}}" Fill="Blue"/>;
但是如果我想让高度总是等于宽度的一半,代码不正确:<Rectangle Width="50" Height="{Binding Path=Width/2,RelativeSource={RelativeSource Self}}" Fill="Blue"/>,那么如何在 XAML 中做到这一点?
【问题讨论】:
-
写一个绑定转换器
-
您不能在 XAML 中进行计算,但是您可以应用一些转换器来为您完成计算。见:stackoverflow.com/questions/8874404/…