how to text-align columns in DataGrid? (style DataGridCell)

Posted by Olga on Stack Overflow See other posts from Stack Overflow or by Olga
Published on 2014-06-06T09:13:19Z Indexed on 2014/06/06 9:25 UTC
Read the original article Hit count: 318

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datagrid