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:
focusmanager.focusedelement="{binding elementname=pwdbox}"
i have created
focusextension
set focus on control.
please help.
another option have create bool isfocused
property 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
Post a Comment