WPF ListBoxItem IsSelected property selects only for an instant -
i have listboxitem template textbox element within. when user clicks textbox, should make listboxitem selecteditem of listbox.
<listbox.itemtemplate> <datatemplate> <dockpanel margin="4,0,4,0"> <textblock text="{binding path=value1, mode=oneway, updatesourcetrigger=propertychanged}" tooltip="{binding path=hint, mode=oneway, updatesourcetrigger=propertychanged}" verticalalignment="center" /> <textbox x:name="textfield" margin="2,0,0,0" width="{binding path=actwidth, mode=oneway}" visibility="{binding path=visibleact, mode=oneway}" /> </dockpanel> </datatemplate> </listbox.itemtemplate> i have following trigger make selection:
<listbox.resources> <style targettype="listboxitem"> <style.triggers> <trigger property="iskeyboardfocuswithin" value="true"> <setter property="isselected" value="true" /> </trigger> </style.triggers> </style> </listbox.resources> unfortunately, works instant, when change focus, selection disappears. if remove trigger, works selecting textbox not trigger selection.
what should make selection permanent?
your sample doesn't work because, if trigger false, listboxitem getting value had before triggering. listboxitem 'ehmm, was..'.
so have set selectedvalue adding default setter binds isselected state:
<style targettype="listboxitem"> <setter property="isselected" value="{binding isselected, mode="oneway", relativesource={relativesource self}}" /> <style.triggers> <trigger property="iskeyboardfocuswithin" value="true"> <setter property="isselected" value="true" /> </trigger> </style.triggers> </style> setting default setter isselected oneway binding job. set isselected was, when trigger false.
Comments
Post a Comment