WPF: Setting the Height or Width to Auto in Code

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;

And in VB .NET:

Me.txtName.Width = Double.Nan

Best Regards,
Kevin McNeish
INETA Speaker
Chief Architect, MM .NET Application Framework



5 thoughts on “WPF: Setting the Height or Width to Auto in Code”

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>