For example something like that:
Public Partial Class MyWindow
Public Sub New()
Protected Overrides Sub OnContentRendered(e As EventArgs)
Dim myButton As New Button()
myButton.Content = "_My Button" myGrid.Children.Add(myButton)
myButton.Click += Sub(sender As Object, eventArgs As RoutedEventArgs)
AddHandler myButton.Click, Sub(sender As Object, eventArgs As RoutedEventArgs)
Of course, you can add a button on the event you want, even when the window is already showing.
I demonstrated the most convenient way to add a handler to the invocation list of a routed event instance, with anonymous delegate. Not only you won't need to write method which you don't use otherwise, but you can use handling method with the signature convenient for you, without passing both
parameters if you don't need them.