silverlight 4中datagrid列标题和列内容居中问题

在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}"这个是列头

 

posted @ 2011-01-02 17:20  郭远威  阅读(1735)  评论(1编辑  收藏  举报