R
Rick
I am trying to convert this C# code to VB and do not know how to assign the
event to a variable in VB.Net 2008. (see C# 4th line "var eh =
CollectionChanged")
Can anyone tell me if this is possible in VB?
Rick
C#
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);
}
}
}
VB
Public Shadows Event CollectionChanged As
Specialized.NotifyCollectionChangedEventHandler
Protected Overloads Overrides Sub OnCollectionChanged(ByVal e As
Specialized.NotifyCollectionChangedEventArgs)
Dim eh As Specialized.NotifyCollectionChangedEventHandler =
CollectionChanged()
If eh IsNot Nothing Then
Dim dispatcher As Threading.Dispatcher = (From nh In
eh.GetInvocationList() _
Let dpo = TryCast(nh.Target, DispatcherObject) _
Where dpo IsNot Nothing _
Select dpo.Dispatcher).FirstOrDefault()
If dispatcher IsNot Nothing AndAlso dispatcher.CheckAccess()
= False Then
dispatcher.Invoke(Threading.DispatcherPriority.DataBind,
DirectCast((Function() OnCollectionChanged(e)), Action))
Else
For Each nh As
Specialized.NotifyCollectionChangedEventHandler In eh.GetInvocationList()
nh.Invoke(Me, e)
Next
End If
End If
End Sub
event to a variable in VB.Net 2008. (see C# 4th line "var eh =
CollectionChanged")
Can anyone tell me if this is possible in VB?
Rick
C#
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);
}
}
}
VB
Public Shadows Event CollectionChanged As
Specialized.NotifyCollectionChangedEventHandler
Protected Overloads Overrides Sub OnCollectionChanged(ByVal e As
Specialized.NotifyCollectionChangedEventArgs)
Dim eh As Specialized.NotifyCollectionChangedEventHandler =
CollectionChanged()
If eh IsNot Nothing Then
Dim dispatcher As Threading.Dispatcher = (From nh In
eh.GetInvocationList() _
Let dpo = TryCast(nh.Target, DispatcherObject) _
Where dpo IsNot Nothing _
Select dpo.Dispatcher).FirstOrDefault()
If dispatcher IsNot Nothing AndAlso dispatcher.CheckAccess()
= False Then
dispatcher.Invoke(Threading.DispatcherPriority.DataBind,
DirectCast((Function() OnCollectionChanged(e)), Action))
Else
For Each nh As
Specialized.NotifyCollectionChangedEventHandler In eh.GetInvocationList()
nh.Invoke(Me, e)
Next
End If
End If
End Sub