#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");
        }

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #608 – Class Handlers Are Invoked Before Instance Handlers

  1. Pingback: Dew Drop – July 23, 2012 (#1,369) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: