xaml - How to show focus rectangle when the item in list is selected in WPF -


i want show focus rectangle of item when selected.

because isfocusedproperty read-only, can't xaml.

how can show focused rectangle...

any appreciated.

the focus rectangle part of keyboard focus, , displayed when user uses keyboard set focus input element. tested out manually setting keyboard focus (using keyboard.focus()), doesn't seem work.

so i'd recommend creating custom style simulate focus rect when listboxitem selected. came style below seems work. matches focus rect's dash array doesn't strange when real focus rect displayed.

<controltemplate targettype="{x:type listboxitem}">   <grid>     <border background="{templatebinding background}">       <contentpresenter margin="{templatebinding padding}"/>     </border>   </grid>   <controltemplate.triggers>     <trigger property="isselected" value="true">       <setter property="background" value="green"/>       <setter property="foreground" value="white"/>     </trigger>   </controltemplate.triggers> </controltemplate> 

this gives lot more control on how listboxitem displayed in general. adapt other list types (listviewitem, etc.)


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -