Prev | Current Page 301 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

Most important, it doesn??™t allow you to take full advantage of the
routed event model. For that reason, you might choose to attach event handlers using event
attributes in your XAML markup. The event attribute is named after the event you want to
handle, and its value is the name of the event handler method. Here??™s an example that uses
this syntax to connect the MouseUp event of the Image to an event handler named
img_MouseUp:
Name="img" MouseUp="img_MouseUp" />
The code in this book always uses event attributes to connect event handlers in the XAML
markup.
Although it??™s not required, it??™s a common convention to name event handler methods in
the form ElementName_EventName. If the element doesn??™t have a defined name (presumably
because you don??™t need to interact with it in any other place in your code), consider using the
name it would have:

nTip It may be tempting to attach an event to a high-level method that performs a task, but you??™ll have
more flexibility if you keep an extra layer of event handling code. For example, when you click a button
named cmdUpdate, it shouldn??™t trigger a method named UpdateDatabase() directly. Instead, it should call an
event handler such as cmdUpdate_Click(), which can then call the UpdateDatabase() method that does the
real work.


Pages:
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313