考虑如下的层次结构:
Parent Grid -> Detail Grid -> Detail of Detail Grid
其中每个包含其后的网格。现在,我想从Detail of Detail Grid中触发一个事件。我已按照以下方式设置我的处理程序和事件。
public static readonly RoutedEvent DetailofDetailVmClickedEvent =
EventManager.RegisterRoutedEvent("DetailofDetailVmClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(RepoBreakdownRecordControl));
public event RoutedEventHandler DetailofDetailVmClicked
{
add { AddHandler(DetailofDetailVmClickedEvent, value); }
remove { RemoveHandler(DetailofDetailVmClickedEvent, value); }
}
public void RaiseDetailofDetailVmClickedEvent()
{
var args = new RoutedEventArgs(DetailofDetailVmClickedEvent);
args.Source = MyDetailOfDetailGrid.GetFocusedRow() as DetailofDetailVm;
RaiseEvent(args);
}
private void MyDetailOfDetailGrid_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
RaiseDetailofDetailVmClickedEvent();
}
我想在Parent Grid
级别处理此问题。由于我无法直接挂钩到Detail of Detail Grid
事件处理程序(Parent Grid
,Detail Grid
和Detail of Detail Grid
都是他们自己的控件),我该如何实现这一点?
我很高兴地承认,我可能因为缺少咖啡而有了脑力,但这就是生活。
答案 0 :(得分:0)
叹息。喝咖啡的时间。
我只需要将以下内容添加到Parent Grid
的构造函数中。
public ParentGridControl()
{
AddHandler(DetailOfDetailGridControl.DetailofDetailVmClicked, new RoutedEventHandler(DetailofDetailVmClicked_Handler));
}
private void DetailofDetailVmClicked_Handler(object sender, RoutedEventArgs routedEventArgs)
{
// do things here
}