你怎样在代码后端中将
Height="*"
和 Height="Auto"
设定好并使其生效?对于大多数控件设置 Height = "Auto"
,您需要使用 double.NaN
赋值。
示例:
element.Height = double.NaN;
设置 Width/Height = "*"
(仅适用于一些特定元素,例如ColumnDefinition
和 RowDefinition
)与其他情况略有不同。 Width
/Height
值的类型是GridLength
,而非 double
。
例如(更多示例可在 此 MSDN 页面 上找到):
column1.Width = new GridLength(1, GridUnitType.Auto); // Auto
column2.Width = new GridLength(1, GridUnitType.Star); // *