我有我定义我的事件的类:
public class EventRaiserUtility
{
public event EventHandler updateList;
public void updateListEvent()
{
if (updateList != null)
{
updateList(this, EventArgs.Empty);
}
}
public static EventRaiserUtility raiser = new EventRaiserUtility();
}
这就是我提出我的活动的地方:
EventRaiserUtility.raiser.updateListEvent();
最后这是我试图创建监听器的地方:
...
EventRaiserUtility.raiser.updateList += new EventHandler(raiser_updateList);
//placed in the init method of another class
...
private void raiser_updateList(object sender, EventArgs e)
{
connType = MainWindowViewModel.getTTC();
}
getTTC()
简单地说:此事件必须在更新列表时通知,然后使用with更新另一个列表raiser_updateList
。
但raiser_updateList
永远不会被调用。为什么?我所有的 3 个代码片段都在 3 个不同的类(同一个项目)中,但这不是问题......对吗?