Andrej Tozon's blog

In the Attic


Event handlers and VS2008-B2 WPF designer

Not being able to easily create event handlers for controls' events in Visual Studio's WPF designer posed as a potential turn off and a show stopper for less experienced developers, trying out the early bits of different incarnations of WPF designers. Beta 2 of Visual Studio 2008 (pka "Orcas") adds significant improvement with this issue: to begin with - double clicking on user control in the designer will create the default event handler for that control, as we're used with Windows Forms. Adding other event handlers is done through XAML part of the designer:

Adding event handler

Selecting <New Event Handler> in the above example would create the following code:

private void textBox1_TextChanged(object sender, TextChangedEventArgs e)


And to later navigate to that event handler, there's a context menu navigation option right under your fingers:

Context menu

The best part is that event handler creation isn't limited to single (selected) event handler. If you're starting with pre-created XAML file, and event handler names are already there, but without any generated code, just select all necessary controls and choose "Navigate to Event Handler" from the context menu and all missing handlers will be created for you. Without the actual implementation, of course; this one is still up to you :)