Reputation: 2097
In my WPF app I use a DataGrid, and when I have columns whose header label text is close to the width of the column, the right part of the column header text gets cut off by a region of blankness on the right side of the header area, which is like internal padding just on the right side of the header that is 6 or 8 pixels wide, which seems to have no good reason.
I searched around for similar questions and saw someone mentioning a 0,6, 0,6 padding value that cannot be changed, but I don't know if they were talking about the same thing I am seeing.
Anyway, I would love for someone who knows a workaround to let me know what it is.
Thanks!
Upvotes: 2
Views: 3464
Reputation: 41403
In .NET 4, the DataGridColumnHeader
wraps the header content in an instance of DataGridHeaderBorder
. The DataGridHeaderBorder
does appear to add a padding of "3,3,3,3"
around the content, if it's Padding
property is currently set to "0,0,0,0"
.
There is additional logic based on whether the DataGridHeaderBorder
is being used for the column or row headers. In addition, the various themes have similar, but not exactly the same, logic.
The only way to prevent DataGridHeaderBorder
from adding it's padding is to specify your own. So you can use:
<Style TargetType="DataGridColumnHeader">
<Setter Property="Padding" Value="1,0" />
</Style>
Or anything other than all zeros, such as "0.0001"
or "-1"
. The DataGridColumnHeader
will pass it's padding on to the DataGridColumnHeader
, which is why you can use the implicit style above.
Upvotes: 6