wpf - How to get DataTemplate to fill DataGridTemplateColumn -
i have following xaml creating datagrid:
<datagrid canuseraddrows="false" horizontalalignment="left" name="test" autogeneratecolumns="false" height="164" margin="205,264,0,0" verticalalignment="top" width="511"> <datagrid.columns> <datagridtextcolumn canusersort="false" binding="{binding description, mode=twoway}" header="description" width="6*" isreadonly="true" /> <datagridtemplatecolumn width="2.6*" x:name="parent" > <datagridtemplatecolumn.headertemplate> <datatemplate > <grid showgridlines="false" width="{binding elementname=parent,path=width}" > <grid.columndefinitions> <columndefinition width="1*" /> <columndefinition width="1*" /> </grid.columndefinitions> <textblock text="initial " grid.column="0" /> <textblock text="date " grid.column="1" /> </grid> </datatemplate> </datagridtemplatecolumn.headertemplate> <datagridtemplatecolumn.celltemplate> <datatemplate> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> <datagridcheckboxcolumn canusersort="false" binding="{binding stepcomplete, mode=twoway}" header="completed" width="1.5*" isreadonly="true" /> </datagrid.columns> </datagrid>
i have created datagridtemplatecolumn.headertemplate datatemplate inside want create multi header column. issue cannot datatemplate stretch / fill parent cell. have added image below demonstrate problem. please note area highlighted around initial date text datatemplate border. know how can change datatemplate fill parent cell?
thanks callum
to set header cell alignment have use columnheaderstyle:
<datagrid.columnheaderstyle> <style targettype="{x:type datagridcolumnheader}"> <setter property="fontweight" value="bold" /> <setter property="horizontalalignment" value="stretch" /> <setter property="horizontalcontentalignment" value="stretch" /> </style> </datagrid.columnheaderstyle>
i see 2 issues in code:
- you trying binding grid.width property (double) datagridtemplatecolumn.width property value
2.6*
(datagridlength). cannot set2.6*
grid.width, because not valid double value. - datatemplate has own namescope, therefore cannot refer element outside datatemplate using elementname. moreover, datagridtemplatecolumn not uielement , not in visualtree, therefore datagridtemplatecolumn not parent of elements defined in datatemplate. datagridtemplatecolumn used define columns. datagrid generate headers, rows , cells based on definitions, datagridcolumns never gets rendered.
Comments
Post a Comment