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 7563633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:42:49+00:00 2026-05-30T13:42:49+00:00

Possible Duplicate: How would that be possible to remove all event handlers of the

  • 0

Possible Duplicate:
How would that be possible to remove all event handlers of the Click event of a Button?

I want to remove all click event handlers from a button. I found this method in Stack Overflow question How to remove all event handlers from a control.

private void RemoveClickEvent(Button b)
{
    FieldInfo f1 = typeof(Control).GetField("EventClick",
                                            BindingFlags.Static |
                                            BindingFlags.NonPublic);
    object obj = f1.GetValue(b);
    PropertyInfo pi = b.GetType().GetProperty("Events",
                                              BindingFlags.NonPublic |
                                              BindingFlags.Instance);
    EventHandlerList list = (EventHandlerList)pi.GetValue(b, null);
    list.RemoveHandler(obj, list[obj]);
}

But this line always returns null:

  typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);

And this method was written in 2006.

Is there any latest version of this method?

Note: I am working with WPF and .NET 4.0.

  • 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-30T13:42:51+00:00Added an answer on May 30, 2026 at 1:42 pm

    The below is a helpful utility method for retrieving all subscribed event handlers for any routed event:

    /// <summary>
    /// Gets the list of routed event handlers subscribed to the specified routed event.
    /// </summary>
    /// <param name="element">The UI element on which the event is defined.</param>
    /// <param name="routedEvent">The routed event for which to retrieve the event handlers.</param>
    /// <returns>The list of subscribed routed event handlers.</returns>
    public static RoutedEventHandlerInfo[] GetRoutedEventHandlers(UIElement element, RoutedEvent routedEvent)
    {
        // Get the EventHandlersStore instance which holds event handlers for the specified element.
        // The EventHandlersStore class is declared as internal.
        var eventHandlersStoreProperty = typeof(UIElement).GetProperty(
            "EventHandlersStore", BindingFlags.Instance | BindingFlags.NonPublic);
        object eventHandlersStore = eventHandlersStoreProperty.GetValue(element, null);
    
        // Invoke the GetRoutedEventHandlers method on the EventHandlersStore instance 
        // for getting an array of the subscribed event handlers.
        var getRoutedEventHandlers = eventHandlersStore.GetType().GetMethod(
            "GetRoutedEventHandlers", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
        var routedEventHandlers = (RoutedEventHandlerInfo[])getRoutedEventHandlers.Invoke(
            eventHandlersStore, new object[] { routedEvent });
    
        return routedEventHandlers;
    }
    

    Using the above, the implementation of your method becomes quite simple:

    private void RemoveClickEvent(Button b)
    {
        var routedEventHandlers = GetRoutedEventHandlers(b, ButtonBase.ClickEvent);
        foreach (var routedEventHandler in routedEventHandlers)
            b.Click -= (RoutedEventHandler)routedEventHandler.Handler;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Remove from the array elements that are repeated. in Ruby I would
Possible Duplicate: PHP remove special character from string I want to find a regex
Possible Duplicate: undef - Why would you want to undefine a method in ruby?
Possible Duplicate: Remove sensitive files and their commits from Git history I noticed that
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: How to remove nested parentheses in LISP This is my second quick-and-silly
Possible Duplicate: How to remove initial wx.RadioBox selection? I'm working on an application that
Possible Duplicate: Remove item from array by value I am maintaining string lists like
Possible Duplicate: PHP - remove <img> tag from string I have my content like

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.