However, the situation
is different in WPF applications due to their support for the routed event model.
In WPF, if an event doesn??™t need to send any additional details, it uses the RoutedEvent-
Args class, which includes some details about how the event was routed. If the event does need
to transmit extra information, it uses a more specialized RoutedEventArgs-derived object
(such as MouseButtonEventArgs in the previous example). Because every WPF event argument
class derives from RoutedEventArgs, every WPF event handler has access to information
about event routing.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 153
Attaching an Event Handler
As you learned in Chapter 2, there are several ways to attach an event handler. One option
is to add the Handles statement to your event handling method, as shown here:
Private Sub cmdAnswer_Click(ByVal sender As Object, _
ByVal e As RoutedEventArgs e) Handles cmdAnswer.Click
...
End Sub
This is the approach Visual Studio uses when you add event handlers. (You can add an
event handler in Visual Studio by double-clicking an element or using the drop-down lists
that appear at the top of the code window. To use the latter approach, pick the element name
in the list on the left, and then pick the appropriate event in the list on the right.)
Although the Handles statement is a familiar Visual Basic convention, it isn??™t entirely at
home in the WPF world.
Pages:
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312