how to text-align columns in DataGrid? (style DataGridCell)
- by Olga
I use WPF (C #). I use DataGrid.
I want the first column is aligned with the center, the other columns are right-aligned.
I have style:
<Style x:Key="TextInCellCenter" TargetType="{x:Type TextBlock}" >
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
DataGrid:
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn ElementStyle="{StaticResource TextInCellCenter}" Binding="{Binding Path=Name}" />
<DataGridTextColumn Binding="{Binding Path=Number}" />
<DataGridTextColumn Binding="{Binding Path=Number}" />
<DataGridTextColumn Binding="{Binding Path=Number}" />
I have all the columns are right-aligned.
Please tell me, how do I change the first column had a center text-alignment?