Search code examples
c#.netwpfxamlgridviewcolumn

Is there a way to set the width of a GridViewColumn to Auto?


Somewhere in code I have to set the width of a GridViewColumn to 0, and in another place I want to set it to "Auto" just like in the xaml, instead of reinventing what the xaml is doing when using "Auto".

Any ideas on how to do this in code?


Solution

  • I found the answer here.

    col.Width = Double.NaN;
    

    That's actually the default value, so if you don't set Width, the column will be auto-sized by default.