You can subscribe to a bubbling-type routed event in XAML like so:
<Grid Name="ParentGrid" Thumb.DragCompleted="DragCompletedEventHandler">
<!--Some children possibly containing a Thumb-->
</Grid>
In the above example, any Thumb
inside ParentGrid
that raises its DragCompleted
event will eventually call DragCompletedEventHandler
(provided another handler deeper in the tree does not get called first and set RoutedEventArgs.Handled
to True
, which would stop the propagation).
You can accomplish the same thing in code like this:
ParentGrid.AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler(DragCompletedEventHandler));
Where ParentGrid
is the parent control at the level at which you want to listen.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…