Define Click Event in WPF Custom Control ?,


  • Hi,

    I am new to Wpf Custom Control library Project,I needed to Customize the Wpf Button as Glass Style Button.

    I have done ,styling the button as Glassstyle.But i am very Confused how to add Events in my Glassbutton in Wpf Custom library project (

    Please guide me to Define Custom Event in my GlassButton

    Kartheeswaran Jeyakumar

    Monday, July 02, 2012 5:55 AM


  • Hi Jeyakumar,

    To add events to a custom control, you need declare a public static RoutedEvent in your class and use EventManager.RegisterRoutedEvent() method to register these events.

    I wrote an example here that add a Click event to the Custom GlassButton control.

      public class GlassButton : Control
            static GlassButton()
                DefaultStyleKeyProperty.OverrideMetadata(typeof(GlassButton), new FrameworkPropertyMetadata(typeof(GlassButton)));
            public static RoutedEvent ClickEvent=
            EventManager.RegisterRoutedEvent("Click", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GlassButton));
            public event RoutedEventHandler Click
                add { AddHandler(ClickEvent, value); }
                remove { RemoveHandler(ClickEvent, value); }
            protected virtual void OnClick()
                RoutedEventArgs args = new RoutedEventArgs(ClickEvent, this);
            protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)

    It is in C#, you can use conversion tool to convert to

    Have a nice day,

    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 03, 2012 8:14 AM