2

I am able to center the header without any problems but the cell with the checbox... if I set it to HorizontalAlignment=Center it shows all the way in the left, if I change it to HorizontalContentAlignemnt=Center it shows all the way to the right... what am I doing wrong?

<DataGridTemplateColumn Header="Enable?" SortMemberPath="Enable" Width="75">
    <DataGridTemplateColumn.HeaderStyle>
        <Style TargetType="{x:Type DataGridColumnHeader}">
             <Setter Property="HorizontalContentAlignment" Value="Center"/>
        </Style>
    </DataGridTemplateColumn.HeaderStyle>
    <DataGridTemplateColumn.CellTemplate >
     <DataTemplate >
    <CheckBox IsChecked="{Binding Enable, UpdateSourceTrigger=PropertyChanged}">        
</CheckBox>
    </DataTemplate>
       </DataGridTemplateColumn.CellTemplate>
            <DataGridTemplateColumn.CellStyle>
                 <Style TargetType="DataGridCell">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                 <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=Activated}" Value="Yes">
                            <Setter Property="IsEnabled" Value="False" />
                         </DataTrigger>
                 </Style.Triggers>
                 </Style>
         </DataGridTemplateColumn.CellStyle>

jedgard
  • 868
  • 3
  • 23
  • 41

1 Answers1

0

Set HorizontalAlignment Center of DataGridCell like

  <Style TargetType="DataGridCell">
     <Setter Property="HorizontalAlignment"  Value="Center"/>
  </Style>

I have tested it and it is centering the CheckBox

yo chauhan
  • 12,079
  • 4
  • 39
  • 58