ObservableCollection SplitEvents

Collection: SplitEventsObservatorCollection<T>
Extension method: ObservatorCollectionExtensions.SplitEvents(source)


This collection listens to an IObservableCollection<T> and prevents any bulk event from going through by splitting them into multiple events. This is necessary because ListViewCollection does not support bulk updates.


The following example shows how a list of string could become unstable and how to prevent this from happening.

using ZumtenSoft.WpfUtils.Collections;

IObservableCollection<string> items = new ObservableCollection();

// This will generate a "range actions are not supported" exception
listView.DataSource = items;
items.AddRange(new string[] { "Abc", "Def" });

// This will be safe
listView.DataSource = items.SplitEvents();
items.AddRange(new string[] { "Abc", "Def" });

Last edited May 20, 2013 at 12:47 AM by Zumten, version 1


No comments yet.