From personal experience, and then what I gathered on the web. That question seem to be asked A LOT! The main issue here is that by default the WPF Listbox scrolls item by item due to control virtualizing, which means it only creates visual controls when needed. This is vital for good performance if you decide to bind a large item source to the listbox, say… a few hundred items?
Unfortunately without smooth scrolling, most people find the item based scrolling very sudden and jarring and overall a bad user experience. For me the effect was even worse on my project that was for a touch based application, item based scrolling just wouldn't work!
Turning off control virtualization was not an option because of the amount of data my project needed to handle.
So I did what I took a deep dive and starting reading up on how to create a layout panel, how does control virtualization work in wpf, how to support scrolling.
And I came up with this.
An ItemPanel that performs control virtualizing AND implements IScrollInfo. You can get the sample here. So now you too can have a listbox in WPF that supports smooth scrolling AND item virtualizing.
It wasn't too hard to make it actually, all the code was available around the net in separate places, I have no idea why no one had put this together before. Or maybe I wasn't looking hard enough?
Problems With The Code
- The control was designed to work specifically with my project, you should read up on all the links I included in the SmoothVirtualizedPanel.vb file and understand how things work before wondering why it blows up.
- There are parts of the code (particularly in dealing with the ItemGenerator) which I'm not sure how or why it works. So it might blow up in your face.
- If you have no idea what an ItemPanel is, you really should read up on all the links I put on top of the source file before trying to do anything else.
This is pretty much research quality code, and hasn't gone through any optimization and proper error handling yet so copy and pasters beware.
Oh… did I mention the code is in Visual Basic? ;)