WPF event bubbling and tunneling -


i have following 3 nested elements:

when handle event...

e.handled = true; in of previewmouseleftbuttondown methods. keyup event not fired @ all.

when comment-out e.handled = true; works fine.

are events previewmouseleftbuttondown , keyup dependent somehow?
i thought tunneling/bubbling paired events (for example previewkeydown , keydown) dependent on 1 another.

<dockpanel name="level1" previewmouseleftbuttondown="level1_previewmouseleftbuttondown"             keyup="level1_keyup">  <grid name="level2" previewmouseleftbuttondown="level2_previewmouseleftbuttondown"                                                                                                                                  keyup="level2_keyup">    <button height="25"             width="120"            name="level3"             content="button"            click="level3_click"                             previewmouseleftbuttondown="level3_previewmouseleftbuttondown"              keyup="level3_keyup"/ >         </grid> </dockpanel> 

here event implementations:

private void level1_previewmouseleftbuttondown(object sender, mousebuttoneventargs e) {    debug.writeline("level1_previewmouseleftbuttondown"); }  private void level2_previewmouseleftbuttondown(object sender, mousebuttoneventargs e) {    debug.writeline("level2_previewmouseleftbuttondown");         //e.handled = true; }  private void level3_previewmouseleftbuttondown(object sender, mousebuttoneventargs e) {    debug.writeline("level3_previewmouseleftbuttondown"); }  private void level3_click(object sender, routedeventargs e) {    debug.writeline("level3_click"); }  private void level3_keyup(object sender, keyeventargs e) {    debug.writeline("level3_keyup"); }  private void level2_keyup(object sender, keyeventargs e) {    debug.writeline("level2_keyup"); }  private void level1_keyup(object sender, keyeventargs e) {    debug.writeline("level1_keyup"); } 

why not happening same way in following different example?

<stackpanel previewkeydown="stackpanel_previewkeydown" keyup="stackpanel_keyup">         <grid height="100" previewkeydown="grid_previewkeydown" keyup="grid_keyup">             <button x:name="button" content="button" width="100" height="50" margin="201,134,216,-84" previewkeydown="button_previewkeydown" keyup="button_keyup"/>         </grid>     </stackpanel> 

events implementations:

    private void stackpanel_previewkeydown(object sender, keyeventargs e)     {         debug.writeline("stackpanel_previewkeydown " + e.gethashcode());         e.handled = true;     }      private void grid_previewkeydown(object sender, keyeventargs e)     {         debug.writeline("grid_previewkeydown " + e.gethashcode());     }      private void button_previewkeydown(object sender, keyeventargs e)     {         debug.writeline("button_previewkeydown " + e.gethashcode());     }      private void stackpanel_keyup(object sender, keyeventargs e)     {         debug.writeline("stackpanel_keyup " + e.gethashcode());     }      private void grid_keyup(object sender, keyeventargs e)     {         debug.writeline("grid_keyup " + e.gethashcode());     }      private void button_keyup(object sender, keyeventargs e)     {         debug.writeline("button_keyup " + e.gethashcode());     }      private void window_previewkeydown(object sender, keyeventargs e)     {         debug.writeline("window_previewkeydown " + e.gethashcode());     }      private void window_keyup(object sender, keyeventargs e)     {         debug.writeline("window_keyup " + e.gethashcode());     } 

the routedeventargs shared between tunneling , bubbling events, when handle tunneling event bubbling never executed.

more reading on msdn.


Comments