silverlight 4 datagrid中心列标题

时间:2012-10-18 20:10:10

标签: datagrid silverlight-4.0

我无法在silverlight 4中居中列标题。

这是我的静态资源:

<my:CAddTransaction.Resources>
        <Style x:Name="CenterHeaderText" TargetType="sdk:DataGridColumnHeader">
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
        </Style>
 </my:CAddTransaction.Resources>

这是专栏:

 <sdk:DataGridTemplateColumn Header="Include?" HeaderStyle="{StaticResource CenterHeaderText}" >
        <sdk:DataGridTemplateColumn.CellTemplate>
             <DataTemplate>
                   <CheckBox Name="bInclude" IsChecked="{Binding bInclude, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />
             </DataTemplate>
        </sdk:DataGridTemplateColumn.CellTemplate>
 </sdk:DataGridTemplateColumn>

结果是列标题左对齐。

2 个答案:

答案 0 :(得分:0)

这对我有用:

<controls:DataGridTextColumn Binding="{Binding Path=Login}" Header="My Column Title" Width="100">
    <controls:DataGridTextColumn.HeaderStyle>
         <Style TargetType="dataprimitives:DataGridColumnHeader">
             <Setter Property="HorizontalAlignment" Value="Center"/>
         </Style>
    </controls:DataGridTextColumn.HeaderStyle>
</controls:DataGridTextColumn>   

答案 1 :(得分:0)

如果你仍然需要帮助,这对我来说很好。当用户更改列宽时。

<DataGridCheckBoxColumn> 
    <DataGridCheckBoxColumn.HeaderStyle> 
        <Style TargetType="DataGridColumnHeader"> 
            <Setter Property="HorizontalContentAlignment" Value="Center"/> 
        </Style> 
    </DataGridCheckBoxColumn.HeaderStyle> 
</DataGridCheckBoxColumn>