WPF DataGrid Column Width Auto and Scrollbar

user interfacewidthwpfxaml

I have a DataGrid with many columns.

I want Width="Auto" with scrollbar showing everything if window narrower than all columns. If window wider I want columns to span empty space so there is no dead space.

Basically I want the column minimum width to fully fit contents or header. And expand to larger if window wider.

Best Answer

In order to "fill" all horizontal space in WPF DataGrid as you specified, make sure you have these properties set in XAML:

<DataGrid 
   HorizontalAlignment="Stretch" 
   HorizontalContentAlignment="Stretch" 
   ColumnWidth="*" />
Related Topic