Alex Rivera | Logout

Add margin to DataGridTextColumn

Asked 2011-12-20T13:09:02.417
13

How do I add margin or padding to a DataGridTextColumn?

Edit
Report

1 Answer

43

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.

answered 2013-05-03T14:26:49.063

Your Answer