
Chapter 8: Building Desktop Applications with WPF | 233 |
The previous code shows both the old button1_Click (Button1_Click in VB) event handler and the new NewOrderButton_Click event handler. You might wonder why the button1_Click event handler wasn’t deleted when you deleted it from the Click event in the Properties window, but there’s a good reason for this. What if you had already written code in the event handler? VS leans toward the safe side and does not delete your code. Using the previous steps, you have both event handlers sitting
Coding Event Handlers
One of the tasks you might want to do when a user clicks a button is to open a new window. The first thing you’ll need to do is add a new window. To make this work, you would open Solution Explorer,
TIP
The project’s Add New Item context menu includes a Window entry, which can save a couple of clicks when creating a new window.
After the Designer loads, you can quickly open the
C#:
public partial class NewOrder : Window
{
public NewOrder()
{
InitializeComponent();
}
}
VB:
Public Class NewOrder
End Class