How can I automatically (or maybe using a recalculate method) to automatically resize the width of a listview in WPF after items have been changed (e.g. using a new source, filter or just added or changed items manually) in such a way that the width of each column accomodates exactly the width of the largest item length (or column name length)?
1 Answer
Perhaps you could bind the width property to the "largest" item in the list? Guess you could use a custom converter for it...
Cheers --Jocke
3 Comments
Michel Keijzers
I would hope there would be a more 'automated' way. Calculating the largest can be quite tricky (regarding theme, font size etc).
Jocke
I think you are out of look there. But if you don't want to implement the search algorithm yourself perhaps you can use array.Max (for ints) by first extracting the data. How does the list items look? stackoverflow.com/questions/4906725/…
Michel Keijzers
They are strings depending from 1 to 100s of characters, problem is the proportional font of course. It's not a matter of life and death, I currently just use a fixed value which works reasonably well, but I noticed that when I don't specify the width manually initially all columns are equal to the max width string.