Karsten
Karsten

Reputation: 8154

Add margin to DataGridTextColumn

How do I add margin or padding to a DataGridTextColumn?

Upvotes: 13

Views: 10529

Answers (2)

user2023861
user2023861

Reputation: 8208

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.

Upvotes: 43

brunnerh
brunnerh

Reputation: 185445

Use the ElementStyle/EditingElementStyle.

Upvotes: 3

Related Questions