Possible Duplicate:
CollectionView.DeferRefresh() throws exception
What i dont understand:
I have an ObservableCollection which serves as the source collection for a ListCollectionView.
When i modify the ObservableCollection (Clearing and adding new items) in the scope of a DeferRefresh on the ListCollectionView then an exception is thrown.
var observableCollection = new ObservableCollection<string>();
var collectionView = new ListCollectionView(observableCollection);
var items = new List<string> { "1", "2", "3", .. "999" };
using (collectionView.DeferRefresh())
{
observableCollection.Clear();
foreach (string item in items)
{
observableCollection.Add(item);
}
}
throws System.InvalidOperationException : Cannot change or check the contents or Current position of CollectionView while Refresh is being deferred.
It would be nice to not refresh the CollectionView until all the add operations (could be 100-1000) are completed.
How can i achieve this?