我有一个用户控件,我想一个事件成为公众:为什么我不能直接在C#中通过RoutedEventHandler
public event RoutedEventHandler CloseButtonClicked;
但调度此事件,以下不工作:
public MyUserControl()
{
InitializeComponent();
closeButton.Click += CloseButtonClicked;
}
虽然以下确实工作:
public MyUserControl()
{
InitializeComponent();
closeButton.Click += (sender, args) => CloseButtonClicked(sender, args);
}
这是为什么?
你可以显示'CloseButtonClicked'方法的声明吗? – 2014-10-28 13:29:46
@EdChapel它在我的问题的第二行。 – 2014-10-28 14:07:05
是否在'MyUserControl'中真正声明了'CloseButtonClicked'事件(您尝试使用它的同一个类)? – dewaffled 2014-10-28 14:26:54