我有一个标签项,其内容是自定义UserControl。每当从选项卡控件中删除选项卡项时,我都想通知主窗口。我想在UserControl中引发一个事件,并让主窗口处理事件。这是我的代码
在主窗口中:
public static readonly RoutedEvent CloseTabEvent = EventManager.RegisterRoutedEvent(
"CloseTab", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MainWindow));
private void CloseTab(object sender, RoutedEventArgs e)
{
Console.WriteLine("a tab item was removed");
}
在标签控件中:
RaiseEvent( new RoutedEventArgs(MainWindow.CloseTabEvent));
当我运行代码时,没有打印出“删除标签项”。什么是使它运作的正确方法?