WPF Auto height in code

How can I set the Height property of a WPF control in C # code to " Auto "?

 <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition /> </Grid.RowDefinitions> 

I want to reproduce this behavior in code. Any ideas?

+73
c # wpf xaml
Mar 17 '10 at 0:08
source share
2 answers

Perhaps this link will help you.

Sometimes, you may want to programmatically set the height or width of a WPF element for Auto in code. To do this, simply use the value Double.NaN (not a number).

For example, in C #:

this.txtName.Width = Double.NaN;

+114
Mar 17 '10 at 0:26
source share

you can use

 RowDefinition rd = new RowDefinition ();  
 rd.Height = GridLength.Auto;  
 ContentGrid.RowDefinitions.Add (rd);
+72
Mar 31 '10 at 13:07
source share



All Articles