After you have added the appropriate controls to a form and set their properties, the next step is to add code to the form that responds to control events and manipulates the controls.
You can add some kinds of code declaratively in the XAML editor. For example, you can make a trigger respond to a change in a control’s property or to a control’s event.
You can also write Visual Basic source code to respond to control events just as you would in a Windows Forms application. If you double-click a control on the WPF Designer, Visual Studio creates an empty event handler to catch the control’s default event, and it opens the event handler in the code editor.
For example, the following code shows the event handler the IDE built for a Button control. The default event for a Button is Click, so this code is a Click event handler.
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
End Sub
Private Sub Button_Click()
End Sub
Another way to build an event handler and open the code editor is to select the control on the WPF Designer. Then click the Events icon (the lightning bolt) near the top of the Properties window to make the window show a list of events for the control. Double-click an event in the window to open a new event handler for it in the code editor.
You can also create a new event handler for named controls within the code editor. The upper-left part of the code editor displays a drop-down listing the window’s controls. If you select a control from the list, you can then pick an event for that control from a second drop-down in the code editor’s upper right. If you select an event, the code editor makes a corresponding empty event handler.