Reputation: 1145
I just tried using the following XAML in my WPF application.
<DataGridTextColumn Header="Due" Binding="{Binding QTYDue, Mode=OneWay}">
<DataGridTextColumn.CellStyle>
<Style>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
Unfortunately, the behavior is that the previous styling for the control in MahApps Metro is removed. How do I keep the existing style, but just modify this one aspect of it.
Upvotes: 1
Views: 964
Reputation: 13188
Try this:
Style:
<Style x:Key="DatagridCellStyle1"
TargetType="{x:Type DataGridCell}"
BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
XAML:
<DataGridTextColumn Header="DUE"
Binding="{Binding QTYDue}"
CellStyle="{StaticResource DatagridCellStyle1}" />
OR
<DataGridTemplateColumn Header="DUE">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DataGridCell Style="{StaticResource DatagridCellStyle1}">
<TextBlock Text="{Binding QTYDue}"></TextBlock>
</DataGridCell>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Upvotes: 3