Wpf 宽度绑定到带星号的 属性

Wpf Width binding to property with star

能否将 属性 的宽度绑定到对象乘以星号的值,例如,

(Width="{Binding SizeInt*}") 在 xaml?

在后面的代码中你可以这样做:

rect.Width = new GridLength(item.SizeInt, GridUnitType.Star);

我希望能够像这样在xaml中产生同样的效果...

<Rectangle x:Name="rect" Fill="Red" Width="{Binding SizeInt*}"/>

有没有办法使用 xaml 来做到这一点?

尝试绑定到 GridLength 来源 属性:

public GridLength SizeInt => new GridLength(1, GridUnitType.Star);

您可以将 1 替换为任何您想要的值,包括另一个字段的值。