c# - how to put cursor focus on textbox? -
i have wpf usercontrol contains controls , want put focus on textbox tried use "focusmanager.focusedelement" can't type in bacause tab set first control in usercontrol.
<grid> <grid.rowdefinitions> <rowdefinition height="10"/> <rowdefinition height="45"/> <rowdefinition height="160"/> <rowdefinition height="50"/> <rowdefinition height="15"/> <rowdefinition height="272*"/> </grid.rowdefinitions> <button grid.row="1" x:name="btncreationoffre" background="transparent" width ="120" height="35" borderbrush="{x:null}" horizontalalignment="left" click="btncreationoffre_click" margin="0,2,0,8" style="{dynamicresource nv_offrebutton}"/> <button grid.row="1" x:name="btnmodifieroffre" background="transparent" width ="120" height="35" borderbrush="{x:null}" horizontalalignment="left" click="btnmodifieroffre_click" margin="130,2,0,8" style="{dynamicresource modifierbutton}" /> <button grid.row="1" x:name="btnconsulteroffre" width ="120" height="35" content="consulter" horizontalalignment="left" click="btnconsulteroffre_click" margin="260,2,0,8" style="{dynamicresource consulterbutton}" /> <button grid.row="1" x:name="btnsuppoffre" background="transparent" width ="120" height="35" borderbrush="{x:null}" horizontalalignment="left" click="btnsuppoffre_click" margin="390,2,0,8" style="{dynamicresource suppbutton}" /> <rectangle horizontalalignment="stretch" fill="gray" height="2" grid.row="1" verticalalignment="bottom" grid.columnspan="4" /> <grid x:name="gridfocus" grid.row="2" grid.columnspan="4"> <textblock grid.row="0" grid.column="1" horizontalalignment="left" verticalalignment="center">numéro offre</textblock> <textbox x:name="textboxnumoffre" height="30" grid.row="0" grid.column="2" horizontalalignment="stretch" verticalalignment="center" />
what want when open usercontrol can type in textboxshown above named "textboxnumoffre"
try adding method (in xaml.cs) gets called when usercontrol gets loaded:
public yourusercontrol() { initializecomponent(); this.dispatcher.begininvoke((action)delegate { keyboard.focus(textboxnumoffre); }, dispatcherpriority.render); }
Comments
Post a Comment