Files
docs-desktop/dotnet-desktop-guide/net/wpf/events/snippets/how-to-create-a-custom-routed-event/vb/MainWindow.xaml.vb
T
Tris ShoresandAndy De George 51977cea61 Content update - How to create a custom routed event (user story 1878475) (#1289)
* Add article, redirects, toc

* Update dotnet-desktop-guide/net/wpf/events/how-to-create-a-custom-routed-event.md

Co-authored-by: Andy (Steve) De George <[email protected]>

* Update dotnet-desktop-guide/net/wpf/events/snippets/how-to-create-a-custom-routed-event/csharp/CodeSample.csproj

Co-authored-by: Andy (Steve) De George <[email protected]>

* Update dotnet-desktop-guide/net/wpf/events/snippets/how-to-create-a-custom-routed-event/vb/CodeSampleVb.vbproj

Co-authored-by: Andy (Steve) De George <[email protected]>

* Update dotnet-desktop-guide/net/wpf/events/snippets/how-to-create-a-custom-routed-event/WpfControlLibraryCsharp/WpfControlLibrary.csproj

Co-authored-by: Andy (Steve) De George <[email protected]>

* Use local project references

Co-authored-by: Andy (Steve) De George <[email protected]>
2022-02-10 14:49:46 -08:00

40 lines
1.7 KiB
VB.net

Namespace CodeSampleVb
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
' Assign an event handler to CustomButton using the AddHandler statement.
' AddHandler customButton.ConditionalClick, AddressOf Handler_ConditionalClick
' Assign an event handler to CustomButton using the AddHandler method.
' customButton.[AddHandler](WpfControlVb.CustomButton.ConditionalClickEvent,
' New RoutedEventHandler(AddressOf Handler_ConditionalClick))
' Assign an event handler to StackPanel1 using the AddHandler method.
' StackPanel1.[AddHandler](WpfControlVb.CustomButton.ConditionalClickEvent,
' New RoutedEventHandler(AddressOf Handler_ConditionalClick))
End Sub
'<EventHandler>
' The ConditionalClick event handler.
Private Sub Handler_ConditionalClick(sender As Object, e As RoutedEventArgs)
Dim sourceName As String = CType(e.Source, FrameworkElement).Name
Dim senderName As String = CType(sender, FrameworkElement).Name
Debug.WriteLine($"Routed event handler attached to {senderName}, " +
$"triggered by the ConditionalClick routed event raised on {sourceName}.")
End Sub
' Debug output when CustomButton is clicked:
' Routed event handler attached to CustomButton,
' triggered by the ConditionalClick routed event raised on CustomButton.
' Routed event handler attached to StackPanel1,
' triggered by the ConditionalClick routed event raised on CustomButton.
'</EventHandler>
End Class
End Namespace