I have a hierarchical structure of UserControls that I need to have a custom RoutedEvent to work with. What I need is to be able to have
a parameter bubble through the hierarchy of controls with certain controls modifying the parameter so that when the event bubbles up to the base of the hierarchy I have a URI-like parameter that describes the path it took.
So far I have created a class derived from RoutedEventArgs that adds a String parameter to the event argument.
Public Class ShowAsEventArgs Inherits RoutedEventArgs ' Public Sub New(ByVal evt As RoutedEvent, ByVal myName As String) MyBase.New(evt) mFieldPath = myName End Sub ' Private mFieldPath As String ' Public Property FieldPath As String Get Return mFieldPath End Get Set(value As String) mFieldPath = value End Set End Property End Class
I have also defined the routed event in the "BitField" class:
Public Shared ReadOnly ShowAsFieldEvent As RoutedEvent = EventManager.RegisterRoutedEvent("ShowAsField", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(BitField)) ' Public Custom Event ShowAsField As RoutedEventHandler AddHandler(value As RoutedEventHandler) Me.AddHandler(ShowAsFieldEvent, value) End AddHandler RemoveHandler(value As RoutedEventHandler) Me.RemoveHandler(ShowAsFieldEvent, value) End RemoveHandler RaiseEvent(sender As Object, e As BitField.ShowAsEventArgs) Me.RaiseEvent(e) End RaiseEvent End Event
The problem I am having is adding a handler for this event, I tried this in my "Peripheral" class:
AddHandler BitField.ShowAsFieldEvent, AddressOf HandleShowAsFieldEvent
However, I get an error that says that "ShowAsFieldEvent" is not an event of "BitField".
I spite of lots of searches I am unable to find an example of how to do this. Any input would be much appreciated.
Sid.