I was working on custom tab items to go to the tab control. I got some good sample code at Szymon Kobalczyk's blog but it was in C# and the project I'm working on is in VB. Using the standard code translator tool at developer fusion I got pretty close to where I needed to be but got hung up on how to declare my routedEventHandler in VB. The C# code was:
public event RoutedEventHandler CloseTab
{
add { AddHandler(CloseTabEvent, value); }
remove { RemoveHandler(CloseTabEvent, value); }
}
And the VB Code translated to:
Public Custom Event CloseTab As RoutedEventHandler
AddHandler(ByVal value As RoutedEventHandler)
[AddHandler](CloseTabEvent, value)
End AddHandler
RemoveHandler(ByVal value As RoutedEventHandler)
[RemoveHandler](CloseTabEvent, value)
End RemoveHandler
End Event
Visual Studio then threw an error that stated "'RaiseEvent' definition missing for event 'CloseTab'. All of the sample code I was finding on MSDN was in C# so no help there. The blendaholic though pointed me to this article at the Karl on WPF blog that had an example of what I wanted to do. As the error message suggests, in VB you have to have 3 sections to your custom event, an AddHandler, a RemoveHandler, and a RaiseEvent section. So the actual code translation from C# is:
Public Custom Event CloseTab As RoutedEventHandler
AddHandler(ByVal value As RoutedEventHandler)
[AddHandler](CloseTabEvent, value)
End AddHandler
RemoveHandler(ByVal value As RoutedEventHandler)
[ RemoveHandler](CloseTabEvent, value)
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
Me.RaiseEvent(e)
End RaiseEvent
End Event
Hope this helps anyone else who is trying to figure out how to wireup routed event handlers in VB!