Saturday, 15 March 2014

c# - How to style DataGridHeaderColumn.TextBlock -



c# - How to style DataGridHeaderColumn.TextBlock -

i have datagrid command in wpf project, has default template style header column. default header column contains textblock.

what want alter textwrapping property of textblock without changing header template.

i tried set header style below, no luck

<style x:key="datagridheaderstyle" targettype="datagridcolumnheader"> <setter property="textblock.textwrapping" value="wrapwithoverflow" /> <style.resources> <style targettype="{x:type textblock}"> <setter property="textwrapping" value="wrapwithoverflow" /> </style> </style.resources> </style>

why not utilize blend? header's style this:

<style x:key="datagridcolumnheaderstyle1" targettype="{x:type datagridcolumnheader}"> <setter property="verticalcontentalignment" value="center"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type datagridcolumnheader}"> <grid> <themes:datagridheaderborder borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" isclickable="{templatebinding canusersort}" ispressed="{templatebinding ispressed}" ishovered="{templatebinding ismouseover}" padding="{templatebinding padding}" sortdirection="{templatebinding sortdirection}" separatorbrush="{templatebinding separatorbrush}" separatorvisibility="{templatebinding separatorvisibility}"> <contentpresenter horizontalalignment="{templatebinding horizontalcontentalignment}" recognizesaccesskey="true" snapstodevicepixels="{templatebinding snapstodevicepixels}" verticalalignment="{templatebinding verticalcontentalignment}"/> </themes:datagridheaderborder> <thumb x:name="part_leftheadergripper" horizontalalignment="left" style="{staticresource columnheadergripperstyle}"/> <thumb x:name="part_rightheadergripper" horizontalalignment="right" style="{staticresource columnheadergripperstyle}"/> </grid> </controltemplate> </setter.value> </setter> </style>

contentpresenter does't have textblock content.but can edit it's contenttemplate.

<style x:key="columnheadergripperstyle" targettype="{x:type thumb}"> <setter property="width" value="8"/> <setter property="background" value="transparent"/> <setter property="cursor" value="sizewe"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type thumb}"> <border background="{templatebinding background}" padding="{templatebinding padding}"/> </controltemplate> </setter.value> </setter> </style> <style x:key="datagridcolumnheaderstyle" targettype="{x:type datagridcolumnheader}"> <setter property="verticalcontentalignment" value="center"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type datagridcolumnheader}"> <grid> <themes:datagridheaderborder borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" isclickable="{templatebinding canusersort}" ispressed="{templatebinding ispressed}" ishovered="{templatebinding ismouseover}" padding="{templatebinding padding}" sortdirection="{templatebinding sortdirection}" separatorbrush="{templatebinding separatorbrush}" separatorvisibility="{templatebinding separatorvisibility}"> <contentpresenter horizontalalignment="{templatebinding horizontalcontentalignment}" recognizesaccesskey="true" snapstodevicepixels="{templatebinding snapstodevicepixels}" verticalalignment="{templatebinding verticalcontentalignment}"> <contentpresenter.contenttemplate> <datatemplate> <textblock text="{binding}" textwrapping="wrapwithoverflow"/> </datatemplate> </contentpresenter.contenttemplate> </contentpresenter> </themes:datagridheaderborder> <thumb x:name="part_leftheadergripper" horizontalalignment="left" style="{staticresource columnheadergripperstyle}"/> <thumb x:name="part_rightheadergripper" horizontalalignment="right" style="{staticresource columnheadergripperstyle}"/> </grid> </controltemplate> </setter.value> </setter> </style>

by way, utilize blend create more simple .

c# wpf xaml wpf-style

No comments:

Post a Comment