Reusable style for DataGridTextColumn in WPF

141 Views Asked by At

I have set up a DataGrid in a WPF application and have created reusable styles saved in a resource dictionary.

However I am unsure how to set up reusable style for elements that make up a datagrid.

For example right now I have the following style set up for DataGridTextColumn which looks as follows:

<DataGridTextColumn x:Name="nameColumn" MinWidth="51" Width="SizeToCells" Header="Name" Binding="{Binding Name}" >
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="TextBlock">
                    <Setter Property="Margin" Value="0,5,40,5"></Setter>
                </Style>
            </DataGridTextColumn.ElementStyle>                    
</DataGridTextColumn>

However I don't want to paste in this code for every column in my project and I am unsure how to set this up in my style resource dictionary as reusable code which I can reference to achieve the cellpadding I require on all columns

0

There are 0 best solutions below