views:

757

answers:

1

Are there in general any known performance issues in WPF related to grid column resizing?

I have an application where I need to do some particular things in a column, but for all the different solutions I find the column resizing gets slow. This applies when I have typically more than 1000 elements in my list, but I assume this isn't too much for WPF..? So; the general question is whether you've experienced slow column resizing, and whether you've found solutions for this? What was causing it?

Some more details about my particular case:

I can have two different things in my columns; ComboBox or TextBlock. The ComboBox should fill the whole column and follow on column resize, and clicking an empty area of a column with a TextBlock should select the row. This is where the problem is. For all solutions I have to this the column resizing gets slow. The only way to make resizing smooth that I've found is by adding a StackPanel outside them with Orientation="Horizontal", but with this I'm unable to achieve the styles described above.

Here are some observations:

  • Adding style HorizontalContentAlignment="Stretch" to the items of the list makes the ComboBoxes stretch and the TextBlocks clickable, but also column resize slow.
  • Adding Background="Transparent" to either the StackPanel or the elements that are inserted inside them solves the problem too, but makes resizing slow.
  • Adding an outer StackPanel with property Orientation="Horizontal" makes resizing smooth, but I'm unable to apply the styles as described.
+2  A: 

Have you tried virtualizing the elements in the ListView? When you are virtualizing, the virtualizing panel only creates the visuals for the elements that are in the view. This allows you to have large numbers of items without performance issues like you mention. See VirtualizingStackPanel for more details. Also The Layout System. You can create your own virtualizing panels. If you look up "virtualizing+wpf" on google you'll find lots of hits for virtualizing Canvases, WrapPanels, and etc.

I hope this helps.

Josh G
We have tried virtualizing the elements earlier. I'm not sure whether this solved the resizing problem, but using virtualization scrolling in our list was a terrible experience (slow!), so we couldn't use it. We concluded that this might not be mature yet in WPF after getting the same problem in simpler test applications. Any opinions on this?
stiank81
I know that they made several improvements to virtualization in SP1. First they added deferred scrolling. Second, they added container recycling (as an option). I have never had any problems with using the VirtualizingStackPanel.
Josh G
So, virtualizing solves the problem - though it generates a new one, so you answered the question. Thanks. Actually - the problem turns out to be that we use a TreeView as what we're showing is a tree.. Rewrote it to use ListView instead, and this pretty much solves everything. I might be wrong, but ListViewes seems to be much more mature than TreeView. Will try avoid TreeView from now on. Any opinions on this? Thanks!
stiank81
What version are you running? I've heard that they improved TreeView in 3.5 SP1, but I haven't played with it too much since then. I think they added virtualization, but I don't know about multiple selection. I think you are right. ListBox/ListView has seemed much more stable to me as well.
Josh G
I'm using 3.5 SP1 already.. Still no multi-select. ListView does the job far better for us and solved all our problems, so no more TreeView in this implementation :-)
stiank81