c# - WPF DataGrid Strange Header Padding Behaviour -


in following window, why header have padding of 2/3 though explicitly set 0 using following code? (and can see 0 in snoop):

<datagridtemplatecolumn.headerstyle>     <style targettype="datagridcolumnheader">         <setter property="padding" value="0" />         <setter property="margin" value="0" />     </style> </datagridtemplatecolumn.headerstyle> 

this gives me following (header has padding):

enter image description here

but change other 0, e.g.:

<datagridtemplatecolumn.headerstyle>     <style targettype="datagridcolumnheader">         <setter property="padding" value="0,1" />         <setter property="margin" value="0" />     </style> </datagridtemplatecolumn.headerstyle> 

the padding doesn't set default. assuming there code somewhere in wpf library?

enter image description here

has come across before , figured out why before spend afternoon finding out why?

full test code:

<window x:class="wpfapplication1.gridspacing"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:system="clr-namespace:system;assembly=mscorlib"         mc:ignorable="d"         title="mainwindow" height="350" width="525">     <grid>         <datagrid>             <datagrid.items>                 <system:string>test</system:string>             </datagrid.items>             <datagrid.columns>                 <datagridtemplatecolumn>                     <datagridtemplatecolumn.headertemplate>                         <datatemplate>                             <textblock text="test"                                         background="aquamarine"                                        horizontalalignment="stretch"                                        verticalalignment="stretch"/>                         </datatemplate>                     </datagridtemplatecolumn.headertemplate>                     <datagridtemplatecolumn.headerstyle>                         <style targettype="datagridcolumnheader">                             <setter property="padding" value="0" />                         </style>                     </datagridtemplatecolumn.headerstyle>                     <datagridtemplatecolumn.celltemplate>                         <datatemplate>                                 <textblock text="test" background="aquamarine"/>                         </datatemplate>                     </datagridtemplatecolumn.celltemplate>                 </datagridtemplatecolumn>             </datagrid.columns>         </datagrid>     </grid> </window> 

you can see there datagridheaderborder above contentpresenter using live viusaltree in vs2015.

enter image description here

the datagridheaderborder problem. can refer answer. in datagridheaderborder.cs,

/// <summary> ///     positions children , returns final size of element. /// </summary> protected override size arrangeoverride(size arrangesize) {     if (usingborderimplementation)     {         // revert border implementation         return base.arrangeoverride(arrangesize);     }      uielement child = child;     if (child != null)     {         // use public padding property if it's set         thickness padding = padding;         if (padding.equals(new thickness()))         {             padding = defaultpadding;         }          // reserve space chrome         double childwidth = math.max(0.0, arrangesize.width - padding.left - padding.right);         double childheight = math.max(0.0, arrangesize.height - padding.top - padding.bottom);          child.arrange(new rect(padding.left, padding.top, childwidth, childheight));     }      return arrangesize; } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -