beta.blog

C# – Programmatically set Width/Height attribute to “Auto”

by on Feb.22, 2013, under Programming

I’ve noticed the .Width or .Height attribute expects a Double value in WPF. In contrast to XAML it’s therefor impossible to set one of these attributes to “Auto”. Luckily there’s another way of setting it to Auto from C-Sharp code:

ListView1.Width = Double.NaN;

Double.NaN (or double.NaN) pretty much has the same effect as the Auto attribute in XAML.


1 Comment for this entry

  • vikas bansal

    on toggle button i am changing the height of the panel in wpf

    Double.NaN is not working. Once the size is 0 then I am not able to change it back to auto. How do i do it?

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!