You could probably inherit from ObservableCollection<T>
(or directly implement INotifyCollectionChanged
) to add BeginUpdate
and EndUpdate
methods. Changes made between calls to BeginUpdate
and EndUpdate
would be queued, then combined into one (or several if there are separate ranges) NotifyCollectionChangedEventArgs
object that would be passed to the handlers of the CollectionChanged
event when EndUpdate
is called.
+1
A:
Thomas Levesque
2009-09-09 09:38:52
As far as I know, WPF controls doesn't support range updates for collection, and throw an exception when they receive more than 1 item in one CollectionChanged event.
Tomáš Kafka
2009-11-26 23:34:27
WTF ?! Why provide the ability to specify multiple items in the event args if they don't support it ? I had implemented the collection described in my answer, but hadn't have time to actually test it... I just did, and it seems you're right :(. So my collection can't be used for binding scenarios...
Thomas Levesque
2009-11-26 23:58:26
Not working in WPF 4.0 either :(
Thomas Levesque
2009-11-27 00:03:19
+1
A:
You can find a Thread safe observable collection here. Make your Observable collection thread safe and bind it to listbox.
Sauron
2009-09-09 09:42:58
That's the approach I'm using and it works pretty well. You can use a BackgroundWorker to fill your ObservableCollection and see your ListBox being populated on the fly.
Jalfp
2009-09-09 10:10:49
+2
A:
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
Vault
2009-09-09 10:48:45
The collectionviewsource works efficently when the initial binding takes place, but is very inefficient at runtime.I am now doing the sorting/filtering in the code behind using LINQ
Vault
2009-09-28 09:54:13