c# - Alternating Background Color Grid Rows not working -


i trying implement alternating background color on rows. have itemscontrol itemtemplate in use triggers on style property of border. end royalblue rows instead of alternating red. can somene assist? thank much!

<page.resources>    <datatemplate x:key="mytemplate" >       <grid>          <border borderthickness="1" cornerradius="2" margin="2" verticalalignment="stretch" height="20" width="auto">             <border.style>                <style targettype="{x:type border}">                   <style.triggers>                      <trigger property="itemscontrol.alternationindex" value="1">                         <setter property="background" value="red" />                      </trigger>                      <trigger property="itemscontrol.alternationindex" value="0">                         <setter property="background" value="royalblue" />                      </trigger>                   </style.triggers>                </style>             </border.style>             <grid >                <grid.rowdefinitions>                   <rowdefinition height="auto" />                </grid.rowdefinitions>                <grid.columndefinitions>                   <columndefinition width="*" />                </grid.columndefinitions>                <label grid.column="0" grid.row="0" content="{binding name}"/>             </grid >          </border>       </grid>    </datatemplate> </page.resources>   <scrollviewer >    <stackpanel  >       <itemscontrol itemssource="{binding path=myelements}" itemtemplate="{staticresource mytemplate}" alternationcount="2"/>    </stackpanel> </scrollviewer> 

itemscontrol.alternationindex set against direct child of itemscontrol panel (contentpresenter) need use datatrigger relativesource binding , because it's attached property need put in brackets path=(itemscontrol.alternationindex)

<style targettype="{x:type border}">    <style.triggers>       <datatrigger binding="{binding relativesource={relativesource mode=findancestor, ancestortype={x:type contentpresenter}}, path=(itemscontrol.alternationindex)}" value="1">          <setter property="background" value="red" />       </datatrigger>       <datatrigger binding="{binding relativesource={relativesource mode=findancestor, ancestortype={x:type contentpresenter}}, path=(itemscontrol.alternationindex)}" value="0">          <setter property="background" value="royalblue" />       </datatrigger>    </style.triggers> </style> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -