在ASP.NET中gridview控件,我们可以直接通过设置属性就可以设置列居中了,但是今天发现在silverlight 4中不能那样搞了,设置居中还要额外的加一个

命名空间:xmlns:Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

再通过定义统一资源样式

<Style x:Key="DataGridHeaderStyle" TargetType="Primitives:DataGridColumnHeader">
                <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
            </Style>
            <Style x:Key="DataGridCellStyle" TargetType="data:DataGridCell">
                <Setter Property="HorizontalContentAlignment" Value="Center" ></Setter>
            </Style>

然后在要居中的列引用这个样式如

 CellStyle="{StaticResource DataGridCellStyle}"

 HeaderStyle="{StaticResource DataGridHeaderStyle}"这个是列头

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-12-12
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-22
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案