Is there a way to translate this code in VB? Most of it is easy, but I can't figure out a way to override the event handler.
public class MTObservableCollection<T> : ObservableCollection<T>
{
public MTObservableCollection()
{
_DispatcherPriority = DispatcherPriority.DataBind;
}
public MTObservableCollection(DispatcherPriority dispatcherPriority)
{
_DispatcherPriority = dispatcherPriority;
}
private DispatcherPriority _DispatcherPriority;
public override event NotifyCollectionChangedEventHandler CollectionChanged;
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
var eh = CollectionChanged;
if (eh != null)
{
Dispatcher dispatcher = (from NotifyCollectionChangedEventHandler nh in eh.GetInvocationList()
let dpo = nh.Target as DispatcherObject
where dpo != null
select dpo.Dispatcher).FirstOrDefault();
if (dispatcher != null && dispatcher.CheckAccess() == false)
{
dispatcher.Invoke(DispatcherPriority.DataBind, (Action)(() => OnCollectionChanged(e)));
}
else
{
foreach (NotifyCollectionChangedEventHandler nh in eh.GetInvocationList())
nh.Invoke(this, e);
}
}
}
}
Rewrite Edit:
A conversation that figures it's a compiler implementation snafu and suggests workarounds:
http://social.msdn.microsoft.com/Forums/en/vblanguage/thread/ce30ceed-c260-4d99-b96d-5b7179466be8
This is my (semi) final answer.
It is even an error to override events in C#. The C# Programming Guide says:
I wonder why a framework class breaks this rule, or even why the compiler allows it.