我无法在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>
结果是列标题左对齐。
答案 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>