Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Auto height in code

Tags:

c#

wpf

xaml

How could I set the value of 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 the code behind. Any ideas?

like image 870
Karim Agha Avatar asked Mar 17 '10 00:03

Karim Agha


1 Answers

Perhaps this link will help you.

At times, you may want to programmatically set the Height or Width of a WPF element to Auto in code. To do this, just use the Double.NaN (Not a Number) value.

For example, in C#:

this.txtName.Width = Double.NaN;

like image 115
Zach Johnson Avatar answered Oct 18 '22 21:10

Zach Johnson