如何才有可能删除“按钮”的“点击”事件的所有事件处理程序? [英] How would it be possible to remove all event handlers of the 'Click' event of a 'Button'?

查看:255
本文介绍了如何才有可能删除“按钮”的“点击”事件的所有事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮控制,而且我需要删除所有连接到它的单击事件

怎么会是这样可能吗?

 按钮按钮= 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.

这篇关于如何才有可能删除“按钮”的“点击”事件的所有事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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