WPF ListView性能陷阱
Wednesday, January 7th, 2009
I am using ListView/GridView to low hundred of rows of data, with 10-20 columns with assorted cell templates, and I found that the performance is unacceptable!
Hey a Centrino Pro laptop isn’t that slow, right?
After googling for a night, here are the useful tips I gathered, http://itknowledgeexchange.techtarget.com/wpf/listview-is-it-really-too-slow/,http://www.designerwpf.com/2008/02/12/listview-and-listbox-performance-issues/, http://blogs.msdn.com/jgoldb/archive/2008/03/25/quick-tips-to-improve-wpf-app-memory-footprint.aspx
- Embedding the ListView inside a StackPanel
- Embedding the ListView inside a ScrollViewer
- Not setting ScrollViewer.CanContentScroll to true [Sam: Default is True]
- Having too many columns
- Having UI Virtualization turned off (VirtualizingStackPanel.IsVirtualizing) [Sam: Default is On]
- Avoid grouping
All checked, but it’s still slow! Scrolling is slow, sorting is crawling!
I finally give a try to Snoop, and wahola! Oh my!
It’s not using the VirtualizingStackPanel as the ItemsPanel. Each rows generates about 65 Visual Element, and the number runs into thousands for an hundred rows. No wonder.
Ok, but why?
Turned out that I have a line that reads-
<ListView.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource StandardGroupStyleWithMark}"/>
</ListView.GroupStyle>
Even though I am not using GroupDescription at all, but this enough for WPF to fallback to non-virtualized mode.
Note’s taken!

中文
粵語