Imports System.Windows.Controls.Primitives
Namespace CodeSampleVb
'
' Interaction logic for MainWindow.xaml.
'
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
' Add the new button to the StackPanel.
StackPanel1.Children.Add(CodeButton)
' Remove a handler.
' RemoveHandler XamlButton.Click, AddressOf XamlButton_Click
End Sub
'
' Loaded event handler attached to the XAML page root using Handles.
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
' Handler logic.
Debug.WriteLine($"Loaded event handler attached to Window using Handles.")
End Sub
'
'
' Declare a new button using WithEvents.
Dim WithEvents CodeButton As New Button With {
.Content = "New button",
.Background = Brushes.Yellow
}
' Click event handler attached to CodeButton using Handles.
Private Sub CodeButton_Click(sender As Object, e As RoutedEventArgs) Handles CodeButton.Click
' Handler logic.
Debug.WriteLine($"Click event handler attached to CodeButton using Handles.")
End Sub
'
'
' Click event handler attached to XamlButton using Handles.
Private Sub XamlButton_Click(sender As Object, e As RoutedEventArgs) Handles XamlButton.Click
' Handler logic.
Debug.WriteLine($"Click event handler attached to XamlButton using Handles.")
End Sub
'
End Class
End Namespace