You can declare and register routing events in your custom control, and override the event method:
class MyButton : Button
{
public static readonly RoutedEvent MyEventRoutedEvent =
EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Bubble, typeof(EventHandler<MyEventRoutedEventArgs>), typeof(MyButton));
//CLR
public event RoutedEventHandler MyEvent
{
add { this.AddHandler(MyEventRoutedEvent, value); }
remove { this.RemoveHandler(MyEventRoutedEvent, value); }
}
protected override void OnClick()
{
base.OnClick();
MyEventRoutedEventArgs args = new MyEventRoutedEventArgs(MyEventRoutedEvent, this);
args.ClickTime = DateTime.Now;
this.RaiseEvent(args);
}
}
Declare the MyEventRoutedEventArgs:
class MyEventRoutedEventArgs : RoutedEventArgs
{
public MyEventRoutedEventArgs(RoutedEvent routedEvent, object source) : base(routedEvent, source) { }
public DateTime ClickTime { get; set; }
}
Then you can use it in the control like local:MyEventRoutedEvent.MyEvent="Event_MyEvent"