How do I add margin or padding to a DataGridTextColumn?
Answers without sample code aren't very helpful. Use this:
<DataGridTextColumn Header="Name" Binding="{Binding Name}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="5" />
<Setter Property="Padding" Value="10" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
The x
prefix comes from xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
. I used a business object that has a public Name
property.
Use the ElementStyle
/EditingElementStyle
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With