Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3877572
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:30:48+00:00 2026-05-19T22:30:48+00:00

I am trying to wrap my head around some WPF specific stuff, and have

  • 0

I am trying to wrap my head around some WPF specific stuff, and have yet to find the concrete relation between the UIElement.AddHandler method and the EventManager.RegisterClassHandler method.

I have googled a bit and found this interesting MSDN article:

http://msdn.microsoft.com/en-us/library/ms747183.aspx

Here it states:

“Routed events consider two different types of listeners to the event: class listeners and instance listeners. Class listeners exist because types have called a particular EventManager API, RegisterClassHandler, in their static constructor, or have overridden a class handler virtual method from an element base class. Instance listeners are particular class instances/elements where one or more handlers have been attached for that routed event by a call to AddHandler.”

Alright now so I know the difference between a class and its instance, but somehow I cannot make sense out of this specific part of the document.

Can anyone clear that up for me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:30:48+00:00Added an answer on May 19, 2026 at 10:30 pm

    I don’t know, what exactly do you want to know. Things are pretty simple: you can register handler at instance (object) level, or at class level.

    The difference is, when you register event at class level, it will get called first, before any instance level handlers (of course tunneling or bubbling still takes place before, if handling class is lower/higher in logical tree). So you can handle this event at class level and filter whether this event should be handled by instance or not (by setting e.Handled = true you will stop event for going through other handlers). It may be useful in some cases, but for now I have no example in my mind to share.

    This sample will register event handler that will be called only when event was raised for specific instance of element:

    DockPanel panel = new DockPanel();
    panel.AddHandler(Button.ClickEvent, new RoutedEventHandler(Button_Click));
    

    And this will create event handler, that will be called each time any DockPanel will get Button.Click event, before instance handler of this DockPanel will get called:

    EventManager.RegisterClassHandler(typeof(DockPanel),
        Button.ClickEvent, new RoutedEventHandler(ButtonClass_Click));
    

    If methods were:

    private void ButtonClass_Click(object sender, RoutedEventArgs e)
    {
        Debug.Write("Class level handler");
    }
    
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Debug.Write("Instance level handler");
    }
    

    This would create output:

    Class level handler
    Instance level handler

    But if in class level handler you would set event args to handeled (e.Handled = true;), it would filter out this event for instance level handler (and bubbling up in logical tree).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to wrap my head around asp.net. I have a background as a
Here, is my code. Just trying to wrap my head around some of the
I'm starting Objective-C Development and I'm trying to wrap my head around how some
I'm trying to wrap my head around Object Oriented programming. But I'm having some
I'm trying to wrap my head around organising my code. I have several modules
I'm trying to wrap my head around reflection, so I decided to add plugin
I'm trying to wrap my head around creating a toolbar (a tool band in
I'm trying to wrap my head around SharePoint. Why is it good? Why is
I'm trying to wrap my head around the roles of UIViews and UIViewControllers. If
I'm trying to wrap my head around the best way to use IoC within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.