如何通过事件处理程序传递发件人 [英] How to pass sender through event handler
问题描述
我正在使用 http://wpfmdi.codeplex.com/ 库来处理我的MDI WPF应用程序。
I'm using the http://wpfmdi.codeplex.com/ library to handle MDI in my WPF application.
我有一个Canvas包含一个子容器,它又包含一些小窗口。我想在其中一个小窗口关闭时执行一个动作,所以我试图执行以下操作:
I've got a Canvas which contains a child container, which in turn contains a number of small windows. I would like to perform an action when one of the small windows is closed, so I tried to do the following:
MdiChild child = new MdiChild();
child.Closing += new RoutedEventHandler(DatabaseTableWindow_Closing);
private void DatabaseTableWindow_Closing(object sender, RoutedEventArgs e)
{
object s = e.Source;
}
当窗口关闭时,方法已成功输入, e.Source
为null。我也检查了发件人
,也是空的。所有我想要的是一种查找哪个窗口触发事件的方法。
While the method is successfully entered when a window is closed, e.Source
is null. I've also checked the sender
and that is null too. All I want is a way to find out which window fired the event.
推荐答案
如果 / code>是
null
,那么这听起来像您正在使用的MDI框架中的一个监督/错误。由于您有源代码,您可以修复它:找到关闭
事件引发的地方,并添加此
作为发件人。当您处理该事件时,应该可以引用 MdiChild
。
If the sender
is null
, then it sounds like an oversight/bug in the MDI framework you are using. Since you have the source, you can fix it: locate the place(s) where the Closing
event is raised, and add this
as the sender. That should give you a reference to the MdiChild
when you are handling the event.
这篇关于如何通过事件处理程序传递发件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!