No Events Tab in WPF Designer — No Problem!January 12, 2008 at 11:52 am | Posted in Cider, Visual Studio 2008, WPF | Leave a comment
When I first encountered ‘Cider’, the designer for WPF, I was somewhat shocked and disappointed that the Properties window did not have an Events tab as in the Windows Forms designer where one can easily browse the available events and simply double-click to hook one up to an automatically generated event handler stub. Was I going to have to now rely on the documentation to find the events and carefully type in the connection code and handler?
I said, “Very inconvenient! Too much work. I’ll stick to Forms!” From the forums, I see that I was not alone.
Fortunately, Intellisense makes this a non-issue. Just know the technique:
In Xaml, put your cursor after the control’s tag (Button, Ellipse, Grid etc) and press the spacebar. Intellisense will list all of the properties and events that are available. Note the events are marked with the lightning bolt. Select an event from the list and hit the tab key twice. This will add the event to the control’s attribute list and add an event handler stub in your code behind.
Note that the effort is almost identical to using the Events tab in Windows Forms. The only difference is that you have to scroll through a combined list of properties and events and instead of double clicking, you ‘double tab’.
Or, if you wish, in the code behind, in the window (or page) constructor, type the name of the control (button1 for example) then a ‘.’. Intellisense will list all properties, methods and events. Select the event. Then type ‘+=’ and hit the tab key twice. Your event will be hooked up along with an event handler stub. (This is the same as designing with Forms.)
Of course there are some common default events that can be hooked up just by double clicking on the object in the designer. That is, if you double click on a button in the designer, you get a Button_Click event hookup.
The only thing that is really lacking is the little synopsis of what the event does that is provided by the Properties/Events window in the Forms designer; however, the event names are usually pretty self explanatory.
Hooking up events in the WPF designer are no big deal thanks to the Intellisense support and a little knowledge of how to use it.