如何调用从另一个方法获取发送者和e参数的方法? [英] How can i call A Method taking sender and e parameters from another method?

查看:80
本文介绍了如何调用从另一个方法获取发送者和e参数的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


1-

Hello everyone


1-

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



2-



2-

private void LoadTheme()
      {
       call the previous method from here
      }




我想从2调用方法1

提前thx:)




i want to call method 1 from 2

thx in advance :)

推荐答案

首先,它本质上与WPF无关.您可以从问题中删除该标签.此外,您没有正确指定要执行的操作.如果您不知道参数的值,则如何调用一个接受两个参数的方法?这不是技术问题,这取决于您的工作.

但是,我可以猜到.如果您知道自己真正想要的是什么,您只需提到您的问题与事件处理有关(通常,您的问题中没有任何东西可以识别任何与事件相关的问题;但是我可以通过方法签名和草率地命名许多初学者来猜测它)采用).您可能希望对事件和显式调用采取相同的操作.我还可以猜测,您实际上并没有真正使用方法参数sendere.

我不知道为什么有这么多人陷在这样一个简单的问题上.调用甚至处理程序是否没有道理很明显吗?显然,您需要做的很明显:从even处理程序中调用第二个方法.但这并不是全部.如果您不关心参数,那么为什么需要该处理程序方法?匿名方法会更好.

抱歉,我不知道您正在使用什么事件.也许在第二种方法中确实需要一个参数.在所有情况下,请从事件处理程序中调用第二个方法.您没有提供足够的信息,所以我无法显示代码示例.您可以自己解决这个问题,也可以提出足够详细的问题.在这种情况下,请使用改善问题".



—SA
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


我发现它是如此简单..我只需要使用空参数调用该方法

解决方案是:
Default_Theme_Selected(null,null);
就这样
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


这篇关于如何调用从另一个方法获取发送者和e参数的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆