How to say XAML <Button Height=“Auto”/> in code behind?

后端 未结 1 1347
执念已碎
执念已碎 2021-01-31 15:55

How can you set Height=\"*\" and Height=\"Auto\" in code behind?

相关标签:
1条回答
  • 2021-01-31 16:34

    For setting Height = "Auto" on most controls, you want to assign the value with double.NaN.

    Example:

    element.Height = double.NaN;
    

    Setting Width/Height = "*" ( is a slightly different matter, since it only applies to a select few elements (ColumnDefinition and RowDefinition for example). The type of the Width/Height value is GridLength, rather than double.

    Example (more are given on this MSDN page:

    column1.Width = new GridLength(1, GridUnitType.Auto); // Auto
    column2.Width = new GridLength(1, GridUnitType.Star); // *
    
    0 讨论(0)
提交回复
热议问题