【问题标题】:How to say XAML <Button Height="Auto"/> in code behind?如何在后面的代码中说 XAML <Button Height="Auto"/>?
【发布时间】:2009-09-30 12:53:00
【问题描述】:

如何在后面的代码中设置Height="*"Height="Auto"

【问题讨论】:

    标签: c# wpf xaml autosize


    【解决方案1】:

    要在大多数控件上设置Height = "Auto",您需要使用double.NaN 分配值。

    例子:

    element.Height = double.NaN;
    

    设置Width/Height = "*" ( 稍有不同,因为它只适用于少数几个元素(例如ColumnDefinitionRowDefinition)。Width/Height 值的类型是@987654321 @,而不是double

    示例(更多内容请参见this MSDN page

    column1.Width = new GridLength(1, GridUnitType.Auto); // Auto
    column2.Width = new GridLength(1, GridUnitType.Star); // *
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 2013-09-10
      • 1970-01-01
      • 2017-02-09
      • 2011-12-27
      • 1970-01-01
      • 2012-03-30
      相关资源
      最近更新 更多