WPF - problem with triggers -


i have 2 listviews trigger on selected change background color dark gray , foreground color white. problem when select item in first listview , item in second listview item in first listview foreground doesn't black again , stay white.

alt text

the xaml:

<grid>     <grid.rowdefinitions>         <rowdefinition height="190*" />         <rowdefinition height="121*" />     </grid.rowdefinitions>     <grid.resources>         <resourcedictionary>             <style x:key="@listviewitemstyle" targettype="{x:type listviewitem}">                 <setter property="template">                     <setter.value>                         <controltemplate targettype='{x:type listviewitem}'>                             <grid snapstodevicepixels="true" margin="0">                                 <border x:name="bd" background="{templatebinding background}" borderbrush="{templatebinding borderbrush}"                         borderthickness="{templatebinding borderthickness}" />                                 <gridviewrowpresenter x:name="content" textblock.foreground="{templatebinding foreground}"                         content="{templatebinding content}" columns="{templatebinding gridview.columncollection}" />                             </grid>                             <controltemplate.triggers>                                 <trigger property="isselected" value="true">                                     <setter property="textelement.foreground" value="white" targetname="content" />                                     <setter property="background" value="darkgray" targetname="bd"/>                                 </trigger>                                 <multitrigger>                                     <multitrigger.conditions>                                         <condition property="isselected" value="true" />                                         <condition property="selector.isselectionactive" value="false" />                                     </multitrigger.conditions>                                     <setter property="background" targetname="bd"                             value="{dynamicresource {x:static systemcolors.controlbrushkey}}" />                                     <setter property="foreground" value="{dynamicresource {x:static systemcolors.controltextbrushkey}}" />                                 </multitrigger>                                 <trigger property="isenabled" value="false">                                     <setter property="foreground" value="{dynamicresource {x:static systemcolors.graytextbrushkey}}" />                                 </trigger>                             </controltemplate.triggers>                         </controltemplate>                     </setter.value>                 </setter>             </style>              <datatemplate x:key="@textcelltemplate">                 <textblock text="{binding name}"/>             </datatemplate>              <datatemplate x:key="@trublecelltemplate">                 <rectangle width="20" height="20" fill="black"></rectangle>             </datatemplate>          </resourcedictionary>     </grid.resources>       <listview itemssource="{binding persons}" style="{dynamicresource @listview}" itemcontainerstyle="{dynamicresource @listviewitemstyle}">         <listview.view>             <gridview>                 <gridviewcolumn width="40" celltemplate="{dynamicresource @textcelltemplate}" />                 <gridviewcolumn width="131" celltemplate="{dynamicresource @trublecelltemplate}" />             </gridview>         </listview.view>     </listview>      <listview itemssource="{binding persons}" style="{dynamicresource @listview}" itemcontainerstyle="{dynamicresource @listviewitemstyle}" grid.row="1">         <listview.view>             <gridview>                 <gridviewcolumn width="40" celltemplate="{dynamicresource @textcelltemplate}" />                 <gridviewcolumn width="131" celltemplate="{dynamicresource @trublecelltemplate}" />             </gridview>         </listview.view>     </listview>  </grid> 

you're getting interference between 2 of triggers in template. first isselected trigger becomes active when first select value in listview #1. overrides textblock.foreground value on "content" templatebinding fixed value of white.

when listview #1 loses focus listview #2 second trigger (multitrigger isselected , isselectionactive) activated. causes background of "bd" set different value (same other trigger) and, because it's declared later in triggers collection, overrides previous trigger still active.

the same should happen foreground setter, 1 in multitrigger setting foreground on parent control instead of on "content". because "content" no longer using templatebinding pull in parent control's foreground value first trigger's white value remains active on "content" element.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -