..
End Sub
' The traditional event wrapper.
Public Event Click As RoutedEventHandler
AddHandler(ByVal value As RoutedEventHandler)
MyBase.AddHandler(ButtonBase.ClickEvent, value)
End AddHandler
RemoveHandler(ByVal value As RoutedEventHandler)
MyBase.RemoveHandler(ButtonBase.ClickEvent, value)
End RemoveHandler
End Event
End Class
While dependency properties are registered with the DependencyProperty.Register()
method, routed events are registered with the EventManager.RegisterRoutedEvent() method.
When registering an event, you need to specify the name of the event, the type of routine
(more on that later), the delegate that defines the syntax of the event handler (in this example,
RoutedEventHandler), and the class that owns the event (in this example, ButtonBase).
Usually, routed events are wrapped by ordinary .NET events to make them accessible to
all .NET languages. The event wrapper includes custom AddHandler and RemoveHandler
logic, which is not commonly seen in ordinary VB code. Rather than simply attaching the
event subscriber to the event through the ordinary .NET event system, this code adds and
removes registered callers using the AddHandler() and RemoveHandler() methods, both of
which are defined in the base FrameworkElement class and inherited by every WPF element.
This way, they will receive event notification through the richer WPF routed event system.
Pages:
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309