在我们的WPF应用程序中,我们使用以下方式在窗口的构造函数中添加事件:
AddHandler(Keyboard.KeyUpEvent, (KeyEventHandler)HandleKeyDownEvent);
this.Closing += new System.ComponentModel.CancelEventHandler(WindowF_Closing);
this.Loaded += new RoutedEventHandler(WindowF_Loaded);
在关闭事件中移除这些事件以便窗口被处理,这个想法是否可行:
RemoveHandler(Keyboard.KeyUpEvent, (KeyEventHandler)HandleKeyDownEvent);
this.Closing -= new System.ComponentModel.CancelEventHandler(WindowF_Closing);
this.Loaded -= new RoutedEventHandler(WindowF_Loaded);