(Caveat: I'm primarily a c# developer. My VB should be considered
suspect!)
I pasted your code into VB and removed the explicit delegate creation and let the overload resolution figure out the types for the lambdas:
Function Invoke_CreateTool(Container As StackPanel) As Integer
Dim cntrl = Application.Current.Dispatcher.Invoke(Function() New Button())
Dim Int = Container.Dispatcher.Invoke(Function() Container.Children.Add(cntrl))
Return Int
End Function
VB seems happy with this (at least at compile time).
However, Why are you doing two
Invoke
s? Wouldn't it make more sense to create the
Button
on the same
Dispatcher
that the
Container
uses, since that will certainly be the UI context? Like:
Function Invoke_CreateTool2(Container As StackPanel) As Integer
Return Container.Dispatcher.Invoke(Function()
Return Container.Children.Add(New Button())
End Function)
End Function