The host of routed events are interface elements that have visual entities. Additional events do not have the ability to display the user interface. Two method naming conventions for adding and removing attachment events:
1. The wrapper that joins the additional event listener for the target UI element is aAdd*handlerThe public static method.
The asterisk represents the event name, which is the same as the name of the registration event.
2. The wrapper that relieves the UI element from listening on the attached event is the public static method named Remove*handler , and the asterisk is the event name.
The code is as follows:
public class student{Public int ID {get; set;} public string Name {get; set;} public static readonly RoutedEvent namechangedevent = eventmanager.registerroutedevent ("namechanged", Routingstrategy.bubble, typeof (Routedeventhandler), typeof (Student)); public static void Addnamechangedhandler (DependencyObject D, Routedeventhandler h) { UIElement element = d as UIE lement; if (element! = null) element. AddHandler (Student.namechangedevent, h); } public static void Removenamechangedhandler (DependencyObject D, Routedeventhandler h) { UIElement element = d as UIElement; if (element! = null) element. RemoveHandler (Student.namechangedevent, h); }}
WPF Attach Event definition