What I actually ended up having to do in VB:
Create a new Public Class for my custom commands because it was undesirable to have my MainWindow class as Public:
Public Class Commands
Public Shared myCmd As New RoutedCommand
End Class
Create the Execute and CanExecute methods that run the desired code. These two methods were created in the MainWindow code behind:
Class MainWindow
Private Sub myCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
e.CanExecute = True
e.Handled = True
End Sub
Private Sub myCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
//Do stuff here...
e.Handled = True
End Sub
End Class
Create the Command binding in the MainWindow code-behind and add the two handler methods to the binding (this is the part that is quite different between C# and VB):
Class MainWindow
Public Sub New()
// This call is required by the designer.
InitializeComponent()
//Add any initialization after the InitializeComponent() call.
//Create command bindings.
Dim cb As New CommandBinding(Commands.myCmd)
AddHandler cb.CanExecute, AddressOf myCmdCanExecute
AddHandler cb.Executed, AddressOf myCmdExecuted
Me.CommandBindings.Add(cb)
End Sub
End Class
Add the new custom command to the button object on the UserControl. With a custom command, this did not seem to be possible in XAML, so I had to do it in code-behind. The Commands class needed to be Public so the commands were accessible in this UserControl:
Public Class myUserControl
Public Sub New()
//This call is required by the designer.
InitializeComponent()
// Add any initialization after the InitializeComponent() call.
myButton.Command = Commands.myCmd
End Sub
End Class