c# - Xaml Listbox item focus issue -


i using xaml usercontrol part of wpf application. have created list box have populated data text search. data appears on buttons used select users desired option search.

<scrollviewer horizontalscrollbarvisibility="auto"     verticalscrollbarvisibility="auto"     margin="2">      <listbox itemssource="{binding path=crewoptions}"         horizontalcontentalignment="stretch"         borderthickness="0"         selectionmode="multiple"         name="crewoptionslistbox">          <listbox.itemtemplate>             <datatemplate>                 <button x:name="irrelevant"                     height="28px"                     background="#f4f3e9"                     margin="2,2,2,2"                     content="{binding irrelevant1, targetnullvalue={x:static sys:string.empty}}"                     command="{binding irrelevant2}"/>             </datatemplate>         </listbox.itemtemplate>          <listbox.itemcontainerstyle>             <style targettype="{x:type listboxitem}"             </style>         </listbox.itemcontainerstyle>     </listbox> </scrollviewer> 

this works fine, when tab textbox list box , use arrow keys select option, enter key press not select button. instead, have tab once more focus on button before pressing enter select it.

is there way avoid having hit last tab key focus on button?

open both xaml , c# solutions (preferably mvvm)

hi can add below code in listbox resolve focus issue on listboxitem.

    <listview.itemcontainerstyle>         <style targettype="contentcontrol">             <setter property="focusable" value="false"/>         </style>     </listview.itemcontainerstyle> 

Comments