WPF DataGrid HeaderTemplate Mysterious Padding
- by Jake Wharton
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.
<my:DataGridTemplateColumn>
<my:DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<Button ToolTip="Add New Template" Name="AddNewTemplate" Click="AddNewTemplate_Click">
<Image Source="../Resources/add.png"/>
</Button>
</DataTemplate>
</my:DataGridTemplateColumn.HeaderTemplate>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button ToolTip="Edit Template" Name="EditTemplate" Click="EditTemplate_Click" Tag="{Binding}">
<Image Source="../Resources/pencil.png"/>
</Button>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
When rendered, the header has approximately 10-15px of padding on the right side only which causes the cells to obviously render at that width leaving the cell button having empty space on both sides. Being a pixel-perfectionist this annoys the hell out of me. I had initially thought that it was space for the arrows displayed when sorted but I have sorting disabled on both the entire DataGrid and explicitly on the column.
Here's a image:
I assume this is padding form whatever is the parent element of the button. Does anyone know a way to eliminate it?