#608 – Class Handlers Are Invoked Before Instance Handlers

If you have a class handler defined for a particular routed event, as well as one or more instance handlers on different elements, when the event fires, the class handler will be invoked before any instance handlers.

        public MainWindow()
        {
            this.InitializeComponent();

            // Class handler--called when user clicks on ANY Button
            EventManager.RegisterClassHandler(
                typeof(Button),
                ButtonBase.ClickEvent,
                new RoutedEventHandler(HandleAllButtons));
        }

        private void HandleAllButtons(object sender, RoutedEventArgs e)
        {
            Button b = (Button)e.Source;
            Trace.WriteLine(string.Format("* (CLASS handler) You clicked on [{0}] button", b.Content));
        }

        // Click handler for Eliot button
        private void btnEliot_Click(object sender, RoutedEventArgs e)
        {
            Trace.WriteLine("* (INSTANCE handler) You clicked on Eliot button");
        }