Where is the Events tab in the WPF Designer?
Here's a good question that I got the other day:
"How do I, in Visual Studio, wire up an event handler in the WPF designer without editing the XAML or doing the wiring in code? Where's the Events tab in the Property dialog box like I get in Windows Forms?"
The short answer is that it's not there. The Events tab feature for the WPF Designer didn't make it into Visual Studio 2008. However, there are plenty of easy ways to hook up an event handler:
- In the WPF Designer, you can double-click the control to automatically generate a handler for the default event. For example, if you created a button, just double-click the button on the design surface, and you will be taken to auto-generated event handler code for the Click event.
- In the XAML View, you can use IntelliSense to generate an event handler. Put your cursor after the control whose event you care about, and press space. An IntelliSense dropdown should appear, with all of the control's events (as well as properties). Events are denoted by the lightning bolt. Scroll down through the list until you are highlighting the proper event, and then press tab. Then press tab again to generate a new event handler. Then you can right-click the name of the event handler (it will be of the format "controlName_Event") and select "Navigate to Event Handler". That will take you to the proper place in your code.
- In the Code View, inside the constructor of the Window or Page, type the name of the control whose event you care about, and then type ".". An IntelliSense dropdown should appear, with all of the control's events (as well as properties and methods). Events are denoted by the lightning bolt. Select the appropriate event and press tab. Then type "+=" and press tab twice. This will wire up your event handler and generate the event handler method.
However, the Events tab will be in the WPF Designer in Visual Studio 2008 SP1, as per this announcement.