views:

757

answers:

3

I want to change the alignment of a header on a datagrid in Silverlight, and I can't seem to figure out how to do it. Here's what I have so far:

  <data:DataGridTextColumn Header="#" 
                            IsReadOnly="True"
                            ElementStyle="{StaticResource CenterAlignStyle}" 
                            Binding="{Binding OutlineNumber, Mode=OneWay}" >
    <data:DataGridTextColumn.HeaderStyle>
      <Style TargetType="prim:DataGridColumnHeader">
        <Setter Property="HorizontalAlignment" Value="Center"/>
      </Style>
    </data:DataGridTextColumn.HeaderStyle>
  </data:DataGridTextColumn>

No matter what I try, I can't seem to change the default alignment, which appears to be "left."

+3  A: 

You were really close, its:-

<Setter Property="HorizontalContentAlignment" Value="Center"/>
AnthonyWJones
Actually, this does work! I didn't realize it because I wasn't resizing the column to see that the text does stay aligned to the right on the header. Thanks so much!
Brandon Montgomery
A: 

Nice! Helped me lot!

Svia
A: 

Doesn't quite center the text because of the sort icon being there. Looks off center. Unreal there isn't a simple property to set this without the need for a complete template overhaul.

razor247