WPF DataGrid HeaderTemplate Mysterious Padding

前端 未结 2 1427
闹比i
闹比i 2021-01-21 05:17

I am placing a single button with an image in the header of a column of a DataGrid. The cell template is also just a simple button with an image.



        
相关标签:
2条回答
  • 2021-01-21 05:42

    Using Padding="0,0.000001,0,0" seems to walk around their checking code and works (at least in .NET 4.0).

    0 讨论(0)
  • 2021-01-21 05:54

    Snoop to the rescue!

    Now that you updated the question I found an interesting code in the DataGridHeaderBorder.cs:

       protected override Size ArrangeOverride(Size arrangeSize)
       {
         //...
         if (padding.Equals(new Thickness()))
         {
           padding = DefaultPadding;
         }
         //...
         child.Arrange(new Rect(padding.Left, padding.Top, childWidth, childHeight));
       }
    

    Where DefaultPadding isn't 0... Even though they don't use standard Padding they arrange the child slightly moved.

    How to fix this? Maybe writing your own template for the table header will do the trick. Or you could try negative margins for the image. Don't like neither of this approaches. But I can't find anything better yet.

    0 讨论(0)
提交回复
热议问题