有没有办法在WPF中向我的所有孩子广播RoutedEvent?
例如,假设我有一个有4个孩子的窗口。其中2人知道RoutedEvent的“展示你自己”并正在收听。我如何从窗口发起此事件并将其发送给所有孩子?
我看着
RoutingStrategy
Bubble是错误的方向,Tunnel和Direct不起作用,因为我不知道我想把这个发给哪些孩子。我只是想广播这个消息,让关心它的人处理它。
更新:
我在静态类中声明了事件。
public static class StaticEventClass
{
public static readonly RoutedEvent ClickEvent =
EventManager.RegisterRoutedEvent("Click", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(StaticEventClass));
public static readonly RoutedEvent DrawEvent =
EventManager.RegisterRoutedEvent("Draw", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(StaticEventClass));
}
问题是,当我从窗户里提起这件事时,孩子们从来没有看到过。
RoutedEventArgs args = new RoutedEventArgs(StaticEventClass.DrawEvent, this);
this.RaiseEvent(args);
再次更新。。这是孩子的训练员。
public ChildClass()
{
this.AddHandler(StaticEventClass.DrawEvent, new RoutedEventHandler(ChildClass_Draw));
}