c# - List Box item container style , Data Template with Convertor -
i have list box data template , convertor embedded it.
<datatemplate x:key="datatemplate"> <border x:name="listitemborder" margin="0,2,0,0" verticalalignment="stretch" horizontalalignment="stretch" background="{binding converter={staticresource backgroundconvertor}}"> <grid horizontalalignment="center" verticalalignment="center"> <textblock... <image ... </grid> </border> </datatemplate>
the convertor backgroundconvertor
in above code add green background 2 items among 4 item in list box.
i have applied style list box when tap on item well.
<style x:key="listitemselectorstyle" targettype="listboxitem"> <setter property="background" value="transparent"/> <setter property="borderthickness" value="1" /> <setter property="padding" value="0" /> <setter property="horizontalcontentalignment" value="stretch"/> <setter property="verticalcontentalignment" value="center"/> <setter property ="foreground" value="black" /> <setter property="template"> <setter.value> <controltemplate targettype="listboxitem"> <border x:name="listboxitem" background="{templatebinding background}" horizontalalignment="{templatebinding horizontalalignment}" verticalalignment="{templatebinding verticalalignment}" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}"> <visualstatemanager.visualstategroups> <visualstategroup x:name="commonstates"> <visualstate x:name="normal"/> <visualstate x:name="mouseover"> <storyboard> <objectanimationusingkeyframes storyboard.targetname="listitemborder" storyboard.targetproperty="background"> <discreteobjectkeyframe keytime="0" value="#c9ebf2" /> </objectanimationusingkeyframes> </storyboard> </visualstate> <visualstate x:name="disabled"/> </visualstategroup> <visualstategroup x:name="selectionstates"> <visualstate x:name="unselected"/> <visualstate x:name="selected"> <storyboard> <objectanimationusingkeyframes storyboard.targetname="listitemborder" storyboard.targetproperty="background"> <discreteobjectkeyframe keytime="0" value="#c9ebf2" /> </objectanimationusingkeyframes> </storyboard> </visualstate> </visualstategroup> </visualstatemanager.visualstategroups> <border x:name="listitemborder" borderbrush="transparent" background="#e3e8f0"> <contentcontrol x:name="contentcontainer" contenttemplate="{templatebinding contenttemplate}" content="{templatebinding content}" horizontalcontentalignment="{templatebinding horizontalcontentalignment}" margin="{templatebinding padding}" verticalcontentalignment="{templatebinding verticalcontentalignment}"/> </border> </border> </controltemplate> </setter.value> </setter> </style>
when click on list item style not being applied @ all.the style set background selected item.
what doing wrong here ?
i working on windows phone 8 application.
you must modify visualstate code:
storyboard.targetproperty="{templatebinding background}"
you must set path property when use binding , converter:
background="{binding converter={staticresource backgroundconvertor}, path=property}"
Comments
Post a Comment