Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everyone


1-
C#
private void Default_theme_Selected(object sender, RoutedEventArgs e)
        {do something without using e and sender
         
        }


2-
C#
private void LoadTheme()
      {
       call the previous method from here
      }



i want to call method 1 from 2

thx in advance :)
Posted
Updated 16-Jan-12 9:04am
v3
Comments
BillWoodruff 16-Jan-12 19:10pm    
Okay, you discovered you can use nulls: but I think SAK makes a very important point in his answer: this is poor design. You should make a procedure that does not require parameters and invoke it: and there is no reason to have an EventHandler that is not used as an EventHandler.

In terms of clean code, and future code maintenance, avoiding this "double use" scenario in an EventHandler via passing in nulls ... will pay off, imho.

First of all, it essentially has nothing do to with WPF. You can remove this tag from the question. Also, you did not properly specify what you want to do. If you don't know values of parameters, how do you want to call a method accepting two parameters? This is not a technical question, this is a matter of what you do.

However, I can guess. If you knew what you really want, you would simply mentioned that your problem is related to event handling (formally, there is nothing in your question which identified any event-related issues; but I can guess it by method signature and sloppy naming many beginners use). You probably want the same action in response to the event and in explicit call. I can also guess that you don't really use method parameters sender and e.

I have no idea why so many get stuck at such a simple problem. Isn't it obvious that it make no sense to call and even handler? Apparently, you need to do the obvious: call a second method from the even handler. But this is not all. If you don't care about parameters, why would you need that handler method? An anonymous method would be much better.

Sorry, I don't know what exactly event you are using. Maybe, you really need a parameter in the second method. In all cases, call a second method from the event handler. You did not provide enough information, so I cannot show the code sample. You can figure this out by yourself or ask a question with sufficient detail. In this case, use "Improve question".



—SA
 
Share this answer
 
i found that it's so simple .. i just have to call the method with null parameters

the solution is:
Default_Theme_Selected(null,null);
that's it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900