wpf - Focus Textbox using FocusManager.FocusedElement issue -


i'm trying set keyboard focus textbox included in stackpanel. when iseditmode becomes true want textbox become, default, focused.

i've tried code:

<datatemplate x:key="libraryitemtemplate"> <stackpanel orientation="vertical">     <stackpanel.style>        <style targettype="stackpanel">           <style.triggers>                <datatrigger binding="{binding iseditmode}" value="true">                    <setter property="focusmanager.focusedelement" value="{binding elementname=txtb}"/>                </datatrigger>           </style.triggers>        </style>     </stackpanel.style>      <textblock x:name="txta" text="a" />     <textbox x:name="txtb" text="b" visibility="{binding iseditmode, converter={staticresource boolvisibilitycollapsed}}"/> </stackpanel> </datatemplate> .... <listview x:name="librarylistview" selecteditem="{binding selecteditem,   updatesourcetrigger=propertychanged}" > <listview.view>     <gridview>         <gridviewcolumn celltemplate="{staticresource libraryitemtemplate}"  width="auto"/>     </gridview> </listview.view> 

but problem mouse doesn't marking seems keyboard focus not in textbox , have click mouse once again textbox able input text in textbox.

any idea?

after focusmanager setting focus have handle event , in event have add

<textbox x:name="txtb"           text="b"           gotfocus="txtb_gotfocus"            visibility="{binding iseditmode              , converter={staticresource boolvisibilitycollapsed}}"/>  .... private void txtb_gotfocus(object sender, routedeventargs e) {     this.dispatcher.begininvoke((action)delegate     {        keyboard.focus(txtb);     }, dispatcherpriority.render); } 

thanks lot darlene

and i'm adding answer myself meet sheridan's suggestion lot


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -