publicclassMyButtonSimple: Button { // Create a custom routed event by first registering a RoutedEventID // This event uses the bubbling routing strategy publicstaticreadonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent( "Tap", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyButtonSimple));
// Provide CLR accessors for the event publicevent RoutedEventHandler Tap { add { AddHandler(TapEvent, value); } remove { RemoveHandler(TapEvent, value); } }
// This method raises the Tap event voidRaiseTapEvent() { RoutedEventArgs newEventArgs = new RoutedEventArgs(MyButtonSimple.TapEvent); RaiseEvent(newEventArgs); } // For demonstration purposes we raise the event when the MyButtonSimple is clicked protectedoverridevoidOnClick() { RaiseTapEvent(); } }