ListView (and ListBox) Performance Issues

I was working on one of my projects today and I noticed that one of our popups displaying search results in a ListBox was having really serious performance problems.  After determining that the problem was, in fact, on the WPF side of things, I was somewhat baffled. I wasn’t doing anything that I could think of that should be pushing the limit of what WPF could do.

 Finally, I went looking online for an answer and discovered a list of possible performance killers for the ListView (and ListBox) on Mark Shurmer’s blog. Chief among his no-no’s:

Embedding the ListView inside a StackPanel

Which is exactly what I was doing.

Why is this a problem? To answer that question, let’s take a look at the ItemsPanel at runtime using Snoop. When I place my ListBox into a Grid, here is what my ItemsPanel looks like:

goodItemsPanel

If I change back to what I originally had (my ListBox in a StackPanel), here is what my ItemsPanel looks like:

BadItemsPanel1badItemsPanel2             BadItemsPanel3

That’s actually not even the end of it. That’s about half.

As far as I can tell, all of Mark’s suggestions have to do with making sure that the VirtualizingStackPanel can do what it needs to do in order to keep your program running at a reasonable rate. Good stuff.

2 thoughts on “ListView (and ListBox) Performance Issues

  1. So embedding a ListView or ListBox in a StackPanel can result in performance loss. But this is only if you’re using virtualizingstackpanels right?

Comments are closed.