c# - How to latch the SelectedIndex on a WPF listbox when a child control has focus -


i have

<style x:key="listboxitemstyle" targettype="{x:type listboxitem}">     <style.triggers>         <trigger property="iskeyboardfocuswithin" value="true">             <setter property="isselected" value="true" />         </trigger>     </style.triggers> </style> 

however problem selectedindex returns -1 when give other control on ui focus. behaviour looking listboxitem selected when child gains focus not reset when child loses focus.

replace trigger eventtrigger isselected isn't returning original state:

<eventtrigger routedevent="previewgotkeyboardfocus">     <beginstoryboard>         <storyboard>             <booleananimationusingkeyframes storyboard.targetproperty="isselected">                 <discretebooleankeyframe value="true" keytime="0:0:0" />             </booleananimationusingkeyframes>         </storyboard>     </beginstoryboard>                           </eventtrigger> 

from msdn

unlike trigger, eventtrigger has no concept of termination of state, action not undone once condition raised event no longer true.

ps: have tried selectionmode="single" only.


Comments