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

  • Home
  • SEARCH
  • 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 103589

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:08:52+00:00 2026-05-11T01:08:52+00:00

I would like to pass a reference of a method into another method and

  • 0

I would like to pass a reference of a method into another method and store it as a variable. Later, I would like to use this reference to define an event handler.

When making an event handler, a method reference is passed like:

myButton.Click += new RoutedEventHandler(myButton_Click); 

And if you look at the constructor for ‘RoutedEventHandler’ from intelliSense, it looks like:

RoutedEventHandler(void(object, RoutedEventArgs)) 

What I would like to do is pass the method ‘myButton_Click’ to a different static method and then create an event handler there. How do I pass the reference to the static method? I tried the following but it doesn’t compile:

public class EventBuilder {     private static void(object, RoutedEventArgs) _buttonClickHandler;      public static void EventBuilder(void(object, RoutedEventArgs) buttonClickHandler)     {         _buttonClickHandler = buttonClickHandler;     }      public static void EnableClickEvent()     {         myButton.Click += new RoutedEventHandler(_buttonClickHandler);     } } 

Thanks, Ben

  • 0 0 Answers
  • 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. 2026-05-11T01:08:52+00:00Added an answer on May 11, 2026 at 1:08 am

    To reference a Method Reference (called a delegate in .NET), use the Handler name, rather than the signature.

    public class EventBuilder {     private static RoutedEventHandler _buttonClickHandler;      public EventBuilder(RoutedEventHandler buttonClickHandler)     {         _buttonClickHandler = buttonClickHandler;     }      public static void EnableClickEvent()     {         myButton.Click += new RoutedEventHandler(_buttonClickHandler);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Remove the Shared from your variable and from your property… May 12, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer You should use something like question.UsersReference.EntityKey = new EntityKey("MyEntities.Users", "ID",… May 12, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer Out of interest why aren't you just passing the information… May 12, 2026 at 10:59 pm

Related Questions

I would like to have a method where the parameter could be Int32 or
I am using the following method to reverse geocode a google maps latlng: [GClientGeocoder.getLocations(address:String,
I would like to have a function that modifies some variable list of parameters
My question is pertaining to the best practice for accessing a child object's parent.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.