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: