Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add margin to DataGridTextColumn

How do I add margin or padding to a DataGridTextColumn?

like image 244
Karsten Avatar asked Dec 20 '11 13:12

Karsten


2 Answers

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.

like image 188
user2023861 Avatar answered Nov 10 '22 05:11

user2023861


Use the ElementStyle/EditingElementStyle.

like image 3
H.B. Avatar answered Nov 10 '22 05:11

H.B.