wpf - The Background of the selected row do not change in ListView Control -


i have following listview listview.itemtemplate:

<listview.itemtemplate>     <datatemplate>         <stackpanelname="stackpanel" orientation="horizontal">             <textboxname="textboxorg"                 background="transparent" borderthickness="0" textwrapping="wrap" text="{bindingorgtext}"                 isreadonly="true"/>             <textboxname="textboxnew"                 background="transparent" borderthickness="0" textwrapping="wrap" text="{bindingnewtext}"                 acceptsreturn="true"/>         </stackpanel>     </datatemplate> </listview.itemtemplate> 

and following listviewitemstyle

<style targettype="listviewitem">     <setter property="snapstodevicepixels" value="true" />         <style.triggers>             <trigger property="isselected" value="true">                 <setter property="background" value="lightgoldenrodyellow" />             </trigger>         </style.triggers> </style> 

i want change default 'blue' background color of selected item, when using above code, did not change 'lightgoldenrodyellow' when select item.

how should fix code let work properly?

you need customize controltemplate of listviewitem. otherwise overrides(doesnt use) background trigger defined. here default template customize (i'm using helpful little tool called stylesnooper templates http://wpfwonderland.wordpress.com/2007/01/02/wpf-tools-stylesnooper/):

            <controltemplate targettype="{x:type listboxitem}">                 <border borderthickness="{templatebinding border.borderthickness}" padding="{templatebinding control.padding}" borderbrush="{templatebinding border.borderbrush}" background="{templatebinding panel.background}" name="bd" snapstodevicepixels="true">                     <contentpresenter content="{templatebinding contentcontrol.content}" contenttemplate="{templatebinding contentcontrol.contenttemplate}" contentstringformat="{templatebinding contentcontrol.contentstringformat}" horizontalalignment="{templatebinding control.horizontalcontentalignment}" verticalalignment="{templatebinding control.verticalcontentalignment}" snapstodevicepixels="{templatebinding uielement.snapstodevicepixels}" />                     </border>                 <controltemplate.triggers>                     <trigger property="selector.isselected">                         <setter property="panel.background" targetname="bd">                             <setter.value>                                 <dynamicresource resourcekey="{x:static systemcolors.highlightbrushkey}" />                                 </setter.value>                             </setter>                         <setter property="textelement.foreground">                             <setter.value>                                 <dynamicresource resourcekey="{x:static systemcolors.highlighttextbrushkey}" />                                 </setter.value>                             </setter>                         <trigger.value>                             <s:boolean>                                 true</s:boolean>                             </trigger.value>                         </trigger>                     <multitrigger>                         <multitrigger.conditions>                             <condition property="selector.isselected">                                 <condition.value>                                     <s:boolean>                                         true</s:boolean>                                     </condition.value>                                 </condition>                             <condition property="selector.isselectionactive">                                 <condition.value>                                     <s:boolean>                                         false</s:boolean>                                     </condition.value>                                 </condition>                             </multitrigger.conditions>                         <setter property="panel.background" targetname="bd">                             <setter.value>                                 <dynamicresource resourcekey="{x:static systemcolors.controlbrushkey}" />                                 </setter.value>                             </setter>                         <setter property="textelement.foreground">                             <setter.value>                                 <dynamicresource resourcekey="{x:static systemcolors.controltextbrushkey}" />                                 </setter.value>                             </setter>                         </multitrigger>                     <trigger property="uielement.isenabled">                         <setter property="textelement.foreground">                             <setter.value>                                 <dynamicresource resourcekey="{x:static systemcolors.graytextbrushkey}" />                                 </setter.value>                             </setter>                         <trigger.value>                             <s:boolean>                                 false</s:boolean>                             </trigger.value>                         </trigger>                     </controltemplate.triggers>                 </controltemplate> 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -