Prev | Current Page 299 | Next

Matthew MacDonald

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

(The following section demonstrates both approaches.) Either way, they??™ll be
notified when the RaiseEvent() method is invoked.
As with dependency properties, the definition of a routed event can be shared between
classes. For example, two base classes use the MouseUp event: UIElement (which is the starting
point for ordinary WPF elements) and ContentElement (which is the starting point for
content elements, which are individual bits of content that can be placed in a flow document).
The MouseUp event is defined by the System.Windows.Input.Mouse class. The UIElement and
ContentElement classes simply reuse it with the RoutedEvent.AddOwner() method:
UIElement.MouseUpEvent = Mouse.MouseUpEvent.AddOwner(GetType(UIElement))
All WPF events use the familiar .NET convention for event signatures. That first parameter
of every event handler provides a reference to the object that fired the event (the sender). The
second parameter is an EventArgs object that bundles together any additional details that
might be important. For example, the MouseUp event provides a MouseEventArgs object that
indicates what mouse buttons were pressed when the event occurred:
Private Sub img_MouseUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
End Sub
In Windows Forms applications, it was customary for many events to use the base
EventArgs class if they didn??™t need to pass along any extra information.


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