To raise the event, OnCollectionChanged
should work fine. If you want to query it you have to get more abusive and use reflection (sorry, example is C# but should be virtually identical - I'm not using any language-specific features here):
NotifyCollectionChangedEventHandler handler = (NotifyCollectionChangedEventHandler)
typeof(ObservableCollection<T>)
.GetField("CollectionChanged", BindingFlags.Instance | BindingFlags.NonPublic)
.GetValue(this);
et voila; the handler or handlers (via GetInvocationList()
).
So basically in your example (regarding that post), use:
Protected Overrides Sub OnCollectionChanged(e As NotifyCollectionChangedEventArgs)
If e.Action = NotifyCollectionChangedAction.Add AndAlso e.NewItems.Count > 1 Then
Dim handler As NotifyCollectionChangedEventHandler = GetType(ObservableCollection(Of T)).GetField("CollectionChanged", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(Me)
For Each invocation In handler.GetInvocationList
If TypeOf invocation.Target Is ICollectionView Then
DirectCast(invocation.Target, ICollectionView).Refresh()
Else
MyBase.OnCollectionChanged(e)
End If
Next
Else
MyBase.OnCollectionChanged(e)
End If
End Sub