Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HowTo define the "Auto" Width of the WPF GridView Column in Code?

I want to define the "Auto" width of a GridView Column in the code. How can I do that?

var grid = (GridView)myListview.View;
grid.Columns.Add(new GridViewColumn
{
   Header = "My Header",
   DisplayMemberBinding = new Binding("MyBinding"),
   Width = ??? // Auto
});
like image 508
gsharp Avatar asked Aug 12 '09 12:08

gsharp


1 Answers

GridViewColumn's Width property is of type double, but according to the MSDN page you can set it to Double.NaN ("not a number") to tell it to auto-size.

If you do that, you have to ask for its ActualWidth if you want to know the width it has auto-sized to.

like image 199
Matt Hamilton Avatar answered Oct 22 '22 05:10

Matt Hamilton