wpf - How to get the label to match the grid column width -


i making simple leader board. want team name column label same size grid column located in.

<listview x:name="teamlist" background="#00000000" borderbrush="#00000000">     <listview.view>         <gridview>             <gridview.columnheadercontainerstyle>                 <style>                     <setter property="frameworkelement.visibility" value="collapsed"/>                 </style>             </gridview.columnheadercontainerstyle>              <gridviewcolumn>                 <gridviewcolumn.celltemplate>                     <datatemplate>                         <grid>                             <grid.columndefinitions>                                 <columndefinition width="70"></columndefinition>                                 <columndefinition width="10"></columndefinition>                                 <columndefinition width="*"></columndefinition>                                 <columndefinition width="10"></columndefinition>                                  <!-- more columns points -->                             </grid.columndefinitions>                              <border grid.column="0" borderbrush="#4fd5f4ff" borderthickness="1,1,1,1" cornerradius="8,8,8,8" background="#4fd5f4ff">                                 <label width="50"              horizontalalignment="center" horizontalcontentalignment="center"              verticalalignment="center" verticalcontentalignment="center" fontsize="23" fontweight="bold"              foreground="black">#1</label>                             </border>                              <!-- shortened size of content -->                             <border grid.column="2" borderbrush="#7fd5f4ff" borderthickness="1,1,1,1" cornerradius="8,8,8,8" background="#7fd5f4ff">                                 <label  height="40" content="{binding path=name}"             fontsize="19" fontweight="bold" padding="20 0 0 0"             foreground="black" verticalcontentalignment="center" verticalalignment="center"></label>                             </border>                              <!-- more columns points -->                         </grid>                     </datatemplate>                 </gridviewcolumn.celltemplate>             </gridviewcolumn>         </gridview>     </listview.view> </listview> 

the above lists theme name width of border/label shortened size of actual content.

how can label expand size of grid column * ?

the problem grid sized in gridview according size of it's content. if turn on showgridlines="true" grid can see problem immediately.

to avoid problem, have give grid width.

i looked around the visualtree gridview using snoop, , see there no element stretches fill max amount of space column in gridview, doesn't appear can relativesource binding.

if had single column in gridview though, close binding width of gridviewrowpresenter relativesource binding, , using converter removes x space value account margins

<grid width="{binding path=actualwidth, converter={staticresource myconverter}",     relativesource={relativesource ancestortype={x:type gridviewrowpresenter}}"     ... /> 

but static width easier if available.

of course, if column in gridview, far better served use multiple gridviewcolumns instead of building own grid inside single gridviewcolumn, hb said.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -