| Re: [aus-dotnet] Autosize columns WPF |
- From: Stephen Price
- Subject: Re: [aus-dotnet] Autosize columns WPF
- Date: Tue, 08 Jan 2008 00:00:11 -0800
- Prev by Date: RE: [aus-dotnet] Where to look for the .NET jobs?
- Next by Date: Re: [aus-dotnet] Where to look for the .NET jobs?
- Previous by thread: Re: [aus-dotnet] Autosize columns WPF
- Next by thread: [aus-dotnet] Problem with WM5 accessing windows file share
- Index(es):
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Hey Paul,
thanks for reply. :)
Tried disabling the virtualisation and it was taking 10 seconds (about 9.5 seconds too long) to sort or autosize the columns. That was with report of around 1000 results. (Some searches are limited to 250 but it turns out the reports have no such limit).
I've gone down the measure and set route, as you suggested. The biggest challenge was trying to figure out what column in the Items list was the current column in the GridView. I ended up using a combination of reflection and walking the Visualtree (to find the textblock in the DataTemplate to get the binding). It works nice for up to about 20,000 items (row * columns) before it gets too slow, and then I fall back to measuring the longest string instead of measuring every single string.
Proud of the code, even if it is a hack. :-/
cheers,
Stephen
On 1/7/08, Paul Stovell <lists@xxxxxxxxxxxxxxx> wrote:
Hi Stephen,
How big is your list?
This behaviour is caused by WPF UI virtualization - UI elements for the non-visible items in ListBoxes and ListViews aren't created until the item is visible. One solution would be to disable virtualization (there should be a property on the ListBox named VirtualizingStackPanel.IsVirtualizing or similar). However, this may cause other problems if you have a rather large list.
Given there's no way for WPF to know what the longest item is until it creates UI elements for it, if virtualization is required, your best bet may be to calculate the width manually and set it yourself. I don't expect there's a built in way to do this (AFAIK, of course).
Cheers,
Paul
On 12/28/07, Stephen Price < stephen@xxxxxxxxxxxxxxxx> wrote:On the off chance that some of the WPF people are still about...I'm trying to get a column in a ListView (WPF) to resize to the longest width item in the column, but it seems to only resize to the longest VISIBLE item. If there is an item that is longer off screen then it is ignored. Double clicking on the width edge resizes (same behaviour as Excel on a column edge) to the best fit for visiible items, but then if you scroll down the list and find longer items they are truncated by the resize. Double click again and now they are visible it resizes. I'd like it to resize to the longest one in the list even if it is not visible.I guess its a performance thing but it is risking data gets hidden.cheers,Stephen
(Click here for more information on the aus-dotnet mailling list)
