I have a WPF ListView table that on default sizes the column headers to the width of each header's text. This does not fill the entire table evenly; I have a mass of squeezed columns on the left and a vacant space on the right.
I would like to be able to resize the columns to a width proportional to the longest item in the column's text, of the header or the rows. How would I do this?
What I am currently doing is initially resizing the headers to widths proportional to the headers' text, using the following code (where SearchResultsTable is the ListView):
private void Resize()
{
var width = SearchResultsTable.ActualWidth;
var gridView = SearchResultsTable.View as GridView;
var columns = new GridViewColumnCollection();
if (gridView != null)
{
columns = gridView.Columns;
}
var initialColumnWidths = columns.Sum(column => column.ActualWidth);
var scale = width / initialColumnWidths;
foreach (var column in columns)
{
column.Width = column.ActualWidth * scale;
}
}
However, this only resizes based on the header text width; I don't know how to get the maximum width of the header and rows. Any suggestions?