让所有的附加事件处理程序的WPF控件 [英] Getting all the attached event handlers for a WPF control

查看:128
本文介绍了让所有的附加事件处理程序的WPF控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展我的动态分配的事件按钮的应用程序。现在的事情是,我希望让所有的按钮单击事件发生的事件,我想删除previous处理程序。

I am developing an application where I assign the events for the button dynamically. Now the thing is that I wish to get all the events for the button click event as I wish to remove the previous handlers.

我试图设置事件处理程序为null,如:

I tried setting the event handler to null like:

Button.Click += null;

不过,我收到一个运行时异常空不能分配。

However I received a runtime exception that null cannot be assigned.

我想知道这是已经连接到它的事件,这样我可以删除这些事件。

I wish to know the events which are already attached to it so that I can remove those events.

任何人可以帮助我实现这一目标?

Can anybody help me in achieving this?

推荐答案

您不能分配事件 - 只重视(+ =)和删除。( - =)操作可为客户

You cannot assign events - only attach (+=) and remove (-=) operations are available for clients.

由于+ =和 - =是,外部code可以添加和删除处理一个事件,但不能以任何其他方式获得或修改被允许在声明了事件的类型外的事件,唯一的操作事件处理程序的基本列表

Since += and -= are the only operations that are permitted on an event outside the type that declares the event, external code can add and remove handlers for an event, but cannot in any other way obtain or modify the underlying list of event handlers.

这篇关于让所有的附加事件处理程序的WPF控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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