Since learning WPF, it has been assumed that tunnel routed events were passed by the triggering control to its child controls, and heaven knew that the tunnel routed event was passed from the window to the current element!
Shame on me!
Paste a sample code to illustrate:
<Grid> <BorderHeight= " the"Width= "+"BorderBrush= "Gray"borderthickness= "1" > <StackPanelBackground= "Lightgray"Orientation= "Horizontal"Previewmouseleftbuttonup= "Stackpanel_previewmouseleftbuttonup"MouseUp= "Stackpanel_mouseup"> <TextBlockName= "Yestb"Width= " the"Previewmouseleftbuttonup= "Yestb_previewmouseleftbuttonup"MouseUp= "Yestb_mouseup"Background= "Blue" >Yes</TextBlock> </StackPanel> </Border> </Grid>
Background code:
Private voidYestb_mouseup (Objectsender, MouseButtonEventArgs e) { //MessageBox.Show ("button");e.handled =true; } Private voidStackpanel_mouseup (Objectsender, MouseButtonEventArgs e) { //MessageBox.Show ("Panel"); } Private voidYestb_previewmouseleftbuttonup (Objectsender, MouseButtonEventArgs e) {MessageBox.Show ("Buttonpreview"); } Private voidStackpanel_previewmouseleftbuttonup (Objectsender, MouseButtonEventArgs e) {MessageBox.Show ("Panelpreview"); }
Program Run effect
When you click on the blue area, the "panelpreivew" dialog box pops up before the "Buttonpreview" dialog box pops up.
Study it!
Tunneling Routed Events