c# - Matching listview header to column dynamically uwp -
this how listview looks, headers scale relativepanel outside columns stay same width
<grid name="listviewgrid" horizontalalignment="stretch"> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition /> </grid.rowdefinitions> <grid x:name="listviewgrid" > <grid.columndefinitions> <columndefinition width="*" /> </grid.columndefinitions> <textblock grid.column="0" text="observation id" /> </grid> <listview x:name="listview" grid.row="1" itemssource="{binding observations}" horizontalalignment="stretch"> <listview.itemtemplate> <datatemplate> <grid width="{binding elementname=listviewgrid, path=actualwidth}"> <grid.columndefinitions> <columndefinition width="*" /> </grid.columndefinitions> <textblock grid.column="0" text="{binding observationid}" /> </grid> </datatemplate> </listview.itemtemplate> </listview> </grid>
i've removed things make more readable, appreciated
first of all, makes no sense if set 1 columndefinition
in grid
did in listviewgrid
, in datatemplate
. it's not big problem, guess removed them make code more readable, good.
secondly, in uwp, width="{binding elementname=listviewgrid, path=actualwidth}"
, actualwidth
not dependency property, cannot used data binding. can refer remarks of frameworkelement.actualwidth property.
i guess need stretch listviewitem
, can code this:
<listview> <listview.itemcontainerstyle> <style targettype="listviewitem"> <setter property="horizontalcontentalignment" value="stretch" /> </style> </listview.itemcontainerstyle> ... </listview>
Comments
Post a Comment