i novice wpf. started learning routedevents in wpf. tried sample , met problem
<grid margin="5" name="grid" mousedown="window_mouseup"> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="*"></rowdefinition> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> </grid.rowdefinitions> <label borderbrush="black" borderthickness="1" grid.row="0" margin="5" name="fancylabel" mousedown="window_mouseup" > <stackpanel name="stack" mousedown="window_mouseup"> <textblock margin="3" name="txtblock1"> click </textblock> <textblock margin="50" name="txtblock2" > click me </textblock> </stackpanel> </label> <listbox grid.row="1" margin="5" name="listmessages"/> <button grid.row="3" margin="5" name="cmd_clear" mousedown="cmd_clear_mousedown" >clear</button> </grid>
the handler mousedown event of button different others int tree hierarchy. event not firing..
but if add in .cs file following code
grid.addhandler(uielement.mousedownevent, new mousebuttoneventhandler(window_mouseup),true); stack.addhandler(uielement.mousedownevent, new mousebuttoneventhandler(window_mouseup), true); fancylabel.addhandler(uielement.mousedownevent, new mousebuttoneventhandler(window_mouseup), true); txtblock1.addhandler(uielement.mousedownevent, new mousebuttoneventhandler(window_mouseup), true); txtblock2.addhandler(uielement.mousedownevent, new mousebuttoneventhandler(window_mouseup), true); img1.addhandler(uielement.mousedownevent, new mousebuttoneventhandler(window_mouseup), true); cmd_clear.addhandler(uielement.mousedownevent, new mousebuttoneventhandler(cmd_clear_mousedown), true);
the cmd_clear_mousedown event fired , event bubbled grid , grid fires window_mouseup.
two points:
1) mousedown="window_mouseup"
everywhere intended?
2) why not register click
event clickmode="press"
instead of mousedown
. don't think button
provides/raises mousedown
unless may custom template.
example:
<button grid.row="3" margin="5" name="cmd_clear" clickmode="press" click="cmd_clear_mousedown">clear</button>
Comments
Post a Comment