I\'m hoping to be able to reject some items after they have been added to an ObservableCollection. I am not able to subclass the ObservableCollection or use any sort of view, s
I had tried using setting a flag to request collection add/remove changes and then when the System.Windows.Interop.ComponentDispatcher.ThreadIdle called my handler, doing my add or remove. That works. However, using a try-finally in the collection changed handler to unwire and then rewire that same collection changed event handler also bypassed the re-entrance issue:
private void MyDataGrid_CollectionChanged( object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e )
{
try
{
dgRows.CollectionChanged -= MyDataGrid_CollectionChanged;
switch( e.Action )
{
case NotifyCollectionChangedAction.Add:
if( SomeTestIsTrue() )
dgRows.Add( new vmRowObject() );
break;
}
}
finally
{
dgRows.CollectionChanged += MyDataGrid_CollectionChanged;
}
}