c# - ListView - Stretch header to full width -


i have simple listview inside of grid take full page (see screenshow below). able stretch rows of listview full width of container using style (horizontalcontentalignment), can’t same header. i’m not able set horizontalcontentalignement stretch header (see highlighted in screenshot below).

any idea how accomplish this?

<page.resources>     <style targettype="listviewitem">         <setter property="horizontalcontentalignment" value="stretch" />     </style> </page.resources>  <grid grid.row="1">     <listview x:name="itemlistview" margin="120,0,0,60" selectionmode="none" horizontalcontentalignment="stretch" horizontalalignment="stretch">         <listview.header>             <grid margin="6" horizontalalignment="stretch">                 <grid.columndefinitions>                     <columndefinition width="*" />                     <columndefinition width="*" />                     <columndefinition width="*" />                 </grid.columndefinitions>                 <textblock grid.column="0" text="rank" style="{staticresource titletextstyle}" textwrapping="nowrap" />                 <textblock grid.column="1" text="username" style="{staticresource titletextstyle}" textwrapping="nowrap" />                 <textblock grid.column="2" text="score" style="{staticresource titletextstyle}" />             </grid>         </listview.header>         <listview.itemtemplate>             <datatemplate>                 <grid margin="6" horizontalalignment="stretch">                     <grid.columndefinitions>                         <columndefinition width="*"/>                         <columndefinition width="*"/>                         <columndefinition width="*"/>                     </grid.columndefinitions>                     <textblock grid.column="0" text="{binding rank}" style="{staticresource titletextstyle}" textwrapping="nowrap" />                     <textblock grid.column="1" text="{binding username}" style="{staticresource captiontextstyle}" textwrapping="nowrap" />                     <textblock grid.column="2" text="{binding score}" style="{staticresource bodytextstyle}" />                 </grid>             </datatemplate>         </listview.itemtemplate>     </listview> </grid> 

enter image description here

one way use converter:

<listview itemssource="{binding players}">     <listview.resources>         <rxdummy:multiplyconverter x:key="multiplyconverter"/>     </listview.resources>     <listview.view>         <gridview>             <gridviewcolumn x:name="rank" header="rank" displaymemberbinding="{binding rank}"                             width="{binding actualwidth, mode=oneway, relativesource={relativesource findancestor, ancestortype={x:type listview}},                                          converter={staticresource multiplyconverter},                                          converterparameter=0.33}"/>             <gridviewcolumn header="username" displaymemberbinding="{binding username}"                              width="{binding elementname=rank, path=actualwidth}"/>             <gridviewcolumn header="score" displaymemberbinding="{binding score}"                              width="{binding elementname=rank, path=actualwidth}"/>         </gridview>     </listview.view> </listview> 

public class multiplyconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         var d = system.convert.todouble(value);         double p = system.convert.todouble(parameter,cultureinfo.invariantculture);         return d * p;     }      public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         throw new notimplementedexception();     } } 

Comments