How to say XAML <Button Height="Auto"/> in code behind?
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); // *
Angry Dan
web/software developer, .NET, C#, WPF, PHP, software trainer, English teacher, have philosophy degree, love languages, run marathons my tweets: http://www.twitter.com/edward_tanguay my runs: http://www.tanguay.info/run my code: http://www.tanguay.info/web my publications: PHP 5.3 training video (8 hours, video2brain) my projects: http://www.tanguay.info
Updated on August 18, 2020Comments
-
Angry Dan almost 4 years
How can you set
Height="*"
andHeight="Auto"
in code behind?