本文介绍了我可以问一下如何听一个活动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 谢谢你花一些时间来查看我的问题。我的问题是如何监听事件??? Hi, Thank you for spending some time to view my question. My question is how to listen an event???推荐答案 public class MyClass { public MyClass(/* ... */) { //... } public event System.EventHandler<SomeEventArgs> SomeEvent; }您可以拥有此类的实例,并将事件句柄添加到事件实例的调用列表,一次或多次: you can have an instance of this class and add an event handle to the invocation list of the event instance, once or several times:MyClass instance = MyClass(/* ... */);//...instance.SomeEvent += (sender, eventArgs) => { //... do something, optionally using sender or evenArgs};//...// and, somewhere else, having a reference to the same instance:instance.SomeEvent += (sender, eventArgs) => { DoSomethingElse(eventArgs);};其中 eventArgs 的类型为 SomeEventArgs ,派生自 System.EventArgs 。 请参阅: http://msdn.microsoft.com/en-us/library/vstudio/awbftdfh.aspx [ ^ ], http://msdn.microsoft.com/en-us/library /edzehd2t%28v=vs.110%29.aspx [ ^ ]。 另见我过去的回答: UserControl自定义事件 [ ^ ], WPF:如何在自定义控件中使用事件 [ ^ ]。 上面讨论的所有内容都是完全适用于WPF事件。同时,WPF事件具有高级分类,具有相当高级的功能,远远超出当前主题,但这件事很有用: http://msdn.microsoft.com/en-us/library/ms753115%28v=vs.110%29.aspx [ ^ ]。 -SA where eventArgs is of the type SomeEventArgs, derived from System.EventArgs.Please see:http://msdn.microsoft.com/en-us/library/vstudio/awbftdfh.aspx[^],http://msdn.microsoft.com/en-us/library/edzehd2t%28v=vs.110%29.aspx[^].See also my past answers:UserControl custom event[^],WPF : How to Use Event in Custom Control[^].Everything discussed above is fully applied to WPF events. At the same time, WPF events have advanced classification with quite advanced features which go well beyond the current topic, but this matter is good to know:http://msdn.microsoft.com/en-us/library/ms753115%28v=vs.110%29.aspx[^].—SA 这篇关于我可以问一下如何听一个活动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-23 14:18