I need to display about few million items in WPF ListBox (I am aware how bad idea this is, but I have to do it this way). New items are arriving very quickly, thousands per second, but apart from that no changes are made to the list: items are never removed or modified. I need the LisBox control to be refreshed at least once per second.
I understand that I get UI virtualization "for free" in WPF (I'm using VirtualizedStackPanel
in Recycle
mode and deferred scrolling), but I have to virtualize the data. I'm completely new to WPF so I tried to leverage the best existing solution that I found. It works but flickers each time the count is refreshed, and SelectedItem is lost on each reload (I assume this is because it fires the CollectionChanged
of "Reset" type that reloads the whole collection). I tried to use "Add" event instead of "Reset" but it requires list of items that were actually added to the collection and it doesn't really make any sense to fetch several thousand of objects per second just to pass them to the event and throw them away because they're virtualized anyway. I also tried to just fire PropertyChanged
for Count
property, so that the ListBox would update it's index range/adjust scrollbar, bizzare things started to happen: the scrollbar would adjust to the new count, though list items wouldn't display and still plenty of flickering.
In other words: how do I inform the ListBox control that N
new items were added to the bound collection so that the ListBox will just adjust the scrollbar range (and won't ask me for the added items until they're actually displayed).
I'm using .NET 4.0 and Caliburn.Micro in this project but I doubt that this will affect potential solutions.