Reputation: 189
I currently have a datagrid with a bunch of columns. All of the columns have the following style
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource MetroDataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.ElementStyle>
Instead of repeating this within each DataGridTextColumn how could I assign this to all the columns in a more simple way?
Upvotes: 0
Views: 62
Reputation: 1998
use the DataGridCell and DataGridColumnHeader styles, then just set that style on the DataGrid style.
<Style TargetType="DataGridCell" x:Key="StyledCells">
<!-- Setter Details -->
</Style>
<Style TargetType="DataGridColumnHeader" x:Key="StyledColumnHeader">
<!-- Setter Details -->
</Style>
<Style TargetType="DataGrid">
<Setter Property="ColumnHeaderStyle" Value="{DynamicResource StyledColumnHeader}" />
<Setter Property="CellStyle" Value="{DynamicResource StyledCells}" />
</Style>
Upvotes: 1