c# - Change background color of item after visiting -
i have following code:
<itemscontrol grid.row="1" itemssource="{binding activities}"> <itemscontrol.itemspanel> <itemspaneltemplate> <ctrls:alignablewrappanel maxwidth="400" horizontalcontentalignment="center" horizontalalignment="center" /> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemcontainerstyle> <style targettype="contentpresenter"> <setter property="horizontalalignment" value="center" /> </style> </itemscontrol.itemcontainerstyle> </itemscontrol>
now have background color of each item has been clicked on (which leads page item) changed. on clicking item again, background color should change back.
how can that?
i have looked @ change background color selected listbox item. there answer contains following code:
<style targettype="listboxitem"> <style.triggers> <trigger property="isselected" value="true" > <setter property="fontweight" value="bold" /> <setter property="background" value="transparent" /> <setter property="foreground" value="black" /> </trigger> </style.triggers> <style.resources> <solidcolorbrush x:key="{x:static systemcolors.highlightbrushkey}" color="transparent"/> </style.resources> </style>
alas, can't insert code in code since setting style contentpresenter. besides, not want.
you can combine these styles. there's catch: overriding systemcolors.highlighbrush
won't in windows 8+. plus, need enable multiselect, not available itemscontrol
, listbox
has it. try code:
<listbox itemssource="{binding activities}" selectionmode="multiple"> <itemscontrol.itemspanel> <itemspaneltemplate> <ctrls:alignablewrappanel maxwidth="400" horizontalcontentalignment="center" horizontalalignment="center" /> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemtemplate> <datatemplate> <border> <contentpresenter content="{binding}"/> </border> </datatemplate> </itemscontrol.itemtemplate> <itemscontrol.itemcontainerstyle> <style targettype="listboxitem"> <setter property="horizontalalignment" value="center" /> <setter property="template"> <setter.value> <controltemplate targettype="listboxitem"> <border background="{templatebinding background}"> <contentpresenter content="{templatebinding content}"/> </border> </controltemplate> </setter.value> </setter> <style.triggers> <trigger property="isselected" value="true" > <setter property="fontweight" value="bold" /> <setter property="background" value="yellow" /> <setter property="foreground" value="black" /> </trigger> </style.triggers> </style> </itemscontrol.itemcontainerstyle> </listbox>
Comments
Post a Comment