c# - DataGridTextColumn style with wrap and tooltip -


in c# / wpf application, have datagrid several datagridtextcolumn column using both text wrapping , tooltip.

i write each column (and works fine):

<datagridtextcolumn header="name" binding="{binding name}">     <datagridtextcolumn.elementstyle>         <style>             <setter property="textblock.textwrapping" value="wrap" />         </style>     </datagridtextcolumn.elementstyle>     <datagridtextcolumn.cellstyle>         <style targettype="datagridcell">             <setter property="tooltip" value="some tooltip text" />         </style>     </datagridtextcolumn.cellstyle> </datagridtextcolumn> 

but define common style can set both wrapping , tooltip text, knowing tooltip text different each column. purpose avoid code redundancy , make clearer.

so far, here's style:

<window.resources>     <style x:key="wrapstyle" targettype="{x:type datagridcell}">         <style.setters>             <setter property="template">                 <setter.value>                     <controltemplate targettype="{x:type datagridcell}">                         <textbox text="{binding relativesource={relativesource templatedparent}, path=content.text}" textwrapping="wrap">                             <textbox.tooltip>                                 <tooltip>                                     <tooltip.content>                                         <textblock text="{binding relativesource={relativesource templatedparent}, path=tooltip}" />                                     </tooltip.content>                                 </tooltip>                             </textbox.tooltip>                         </textbox>                     </controltemplate>                 </setter.value>             </setter>         </style.setters>     </style> </window.resources> 

and column:

<datagridtextcolumn header="name" binding="{binding name}" cellstyle="{staticresource wrapstyle}" /> 

the problem can't specify tooltip pass style. there way without writing 5 lines of datagridtextcolumn.cellstyle each column?

modify style -

<window.resources>     <style x:key="wrapstyle" targettype="datagridcell">         <style.setters>             <setter property="template">                 <setter.value>                     <controltemplate targettype="{x:type datagridcell}">                         <textbox text="{binding relativesource={relativesource templatedparent}, path=content.text}" textwrapping="wrap">                             <textbox.tooltip>                                 <tooltip>                                     <tooltip.content>                                         <textblock text="{binding path=tooltip}"></textblock>                                     </tooltip.content>                                 </tooltip>                             </textbox.tooltip>                         </textbox>                     </controltemplate>                 </setter.value>             </setter>         </style.setters>     </style> </window.resources> 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -