Set focus on a textbox control in UserControl in wpf -


i have created usercontrol loaded in view (window) in wpf. in user control have put textbox. unable set focus on text box when view loads. have tried following nothing works me:

  1. focusmanager.focusedelement="{binding elementname=pwdbox}"

  2. i have created focusextension set focus on control.

please help.

another option have create bool isfocusedproperty in view model. can add datatrigger set focus when property true:

in resources section:

<style x:key="selectedtextboxstyle" targettype="{x:type textbox}">     <style.triggers>         <datatrigger binding="{binding isfocused}" value="true">             <setter property="focusmanager.focusedelement"                  value="{binding relativesource={relativesource self}}" />         </datatrigger>     </style.triggers> </style> 

...

<textbox style="{staticresource selectedtextboxstyle}" ... /> 

note @ times, may need set false first focus (only when true):

isfocused = false; isfocused = true; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -