本文介绍了如何才有可能删除“按钮”的“点击”事件的所有事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个按钮控制,而且我需要删除所有连接到它的单击事件。
怎么会是这样可能吗?
按钮按钮= GetButton(); button.Click.RemoveAllEventHandlers();解决方案
您不能,基本上 - 至少不是没有思考和大量grubbiness的
。活动都严格订阅,退订。 - 你不能退订别人的处理程序,任何比你更可以改变别人的对象引用
I have a button control, and I'd need to remove all the event handlers attached to its Click event.
How would that be possible?
Button button = GetButton(); button.Click.RemoveAllEventHandlers();解决方案
You can't, basically - at least not without reflection and a lot of grubbiness.
Events are strictly "subscribe, unsubscribe" - you can't unsubscribe someone else's handler, any more than you can change someone else's reference to an object.
更多推荐
如何才有可能删除“按钮”的“点击”事件的所有事件处理程序?
发布评论