How to say XAML <Button Height =“Auto”/>在代码后面?
如何在代码后面设置Height="*"和Height="Auto" ?
要在大多数控件上设置“ Height = "Auto" ,您需要用double.NaN 。
例:
element.Height = double.NaN;
设置Width/Height = "*" (稍有不同,因为它只适用于选定的几个元素(例如ColumnDefinition和RowDefinition )。 Width / Height值的types是GridLength ,而不是double 。
示例(更多的MSDN页面上给出:
column1.Width = new GridLength(1, GridUnitType.Auto); // Auto column2.Width = new GridLength(1, GridUnitType.Star); // *