【问题标题】:Wpf Width binding to property with starWpf 宽度绑定到带有星号的属性
【发布时间】:2019-07-30 14:39:05
【问题描述】:

你能不能把一个属性的宽度绑定到一个对象乘星的值上,例如,

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

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

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

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

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

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

【问题讨论】:

    标签: c# wpf data-binding width


    【解决方案1】:

    尝试绑定到 GridLength 源属性:

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

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

    【讨论】:

      猜你喜欢
      • 2011-01-18
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      相关资源
      最近更新 更多