Today, in Code Project, a poster asked a question about the best way to insert multiple items in Observable Collection as a bulk insert.
The poster wondered why it was taking so long to add records doing an Add for each item in the collection. NET collections, there’s an Add Range method that allows you to add multiple items in “one hit”, so why isn’t there one in Observable Collection?
Whenever I add an item to this collection, it /does/ fire an event to notify that the collection has changed, yet this isn't reflected on the GUI during run-time unless I attempt to manually resize the window as the program is running, almost as if a resizing the window forces the GUI to refresh.
This ensures that if you provide a new collection for the Parts property, it will rebind (Observable Collection will handle the rest, like notifying when a part is added or removed from the collection).
So, what makes Observable Collection unsuitable for large scale inserts?
Well, the primary reason lies in the fact that an Add operation fires off a Collection Changed event – it’s this event that is contributing to a large part of the slowdown.
I have a rather strange bug in my program that I'm currently wrestling with.
I'm developing an MVVM application, and I have a simple List Box in my View with its Items Source bound to an Observable Collection of strings.