views:

2056

answers:

6

I have a window using a WPF ListView/GridView bound to an ObservableCollection. The performance is utterly horrific. The application chokes trying to load 300-400 items and CPU usage spikes each time an item is added/removed/modified. Profiling doesn't reveal anything obvious.

Anyone have any suggestions?

+1  A: 

First guess, are you making use of complex data templates for each ListViewItem? This might be anything from lots of images, to (old) BitmapEffects, to even lazy-loaded properties that fetch data on demand from a database (which may cause you to perform many db calls to render each visual, depending on how your data model works).

Second guess, is the list itself able to run its load/add/modified/removed routines quickly (meaning the problem occurs when rendering the data), or does the list itself do those jobs slowly (indicating the list is having some kind of issue).

KP Adrian
The DataTemplate being used contains a single TextBlock.
No database calls are made.
Can you share a bit more of your code that reproduces your issue? Maybe a simple new solution that runs the bare minimum to cause it?
KP Adrian
A: 

have you tried virtualization as recommended in this question??

http://stackoverflow.com/questions/296533/wpf-listview-very-slow-performance-why-elementhost-or-other-reason

DouglasH
This will only help if you are explicitly setting the ItemsPanel property to use something other than the default, which is already a VirtualizingStackPanel.
KP Adrian
A: 

Check these properties out:

VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
ScrollViewer.IsDeferredScrollingEnabled="True"
redjackwong
A: 

And the obvious one, make sure you have upgraded to .net 3.5 SP1, there were a lot of performance gains there.

Also it may be worth looking into the WPF datagridview control as a lot of the performance work in .net 3.5 SP1 were so the datagridview would have good performance on large datasets.

http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25047

Jake Ginnivan
+2  A: 

You need to virtualize your ListView's ItemSource as explained in this article: WPF: Data Virtualization on CodeProject by Paul McClean

Soni Ali
A: 

I found this similar post to be of particular help:

http://stackoverflow.com/questions/1273659/virtualizingstackpanel-mvvm-multiple-selection/1273987

Jimmy Lyke