Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing WPF ObservableCollection performance

At present I have two WPF listboxes imitating the following functionality

Word 2007 customize screen
(source: psu.edu)

I am using 2 ObservableCollections to allow users to select whatever items they require (flexibility is the key here). The main issue is that I have thousands of items that are grouped in both listboxes. All in all the design works really well (with a few dozen items), but my stumbling block is when a user copies all the available items from the left to the right as the screen freezes (time to run on a different thread?).

Looking at ObservableCollection it lacks an AddRange method and there are various implementations available on the internet. I also know the CollectionChanged event is needlessly being fired as each item is copied over draining performance horribly.

It may well be that I have to allow users to choose from groups of over 10 000 items in the future, which sounds like a bad idea, but is non-negotiable as the grouping on the listbox (CollectionViewSource) works really well, but has the side effect of switching off the Virtualising of both the listboxes

What can I do to improve the performance when loading a listbox with thousands of items when databound to an ObservableCollection? Are there any AddRange type implementations that you would recommend? Is the only choice I have here to run this on a background thread which seems expensive because I am not loading data from a database?

like image 213
Vault Avatar asked Sep 09 '09 09:09

Vault


Video Answer


1 Answers

I have removed the CollectionViewSource and the grouping and the items are copied over in 1/2 a second, but with the grouping on it can take up to a minute because virtualisation does not work with the grouping.

I will need to decide whether to use the CollectionViewSource

like image 177
Vault Avatar answered Nov 08 '22 18:11

Vault