如何在银光网格中设置列的右对齐方式

时间:2012-01-18 12:19:31

标签: silverlight grid

如何在银光网格中设置列的水平对齐? 请帮忙

我的xaml代码中的

<sdk:DataGrid AutoGenerateColumns="False" ColumnWidth="*" RowDetailsVisibilityMode="Collapsed" x:Name="grdSalesOrder" TabIndex="22" ItemsSource="{Binding Path=PCVSaleOrders}" SelectionMode="Single" Height="{Binding Path=GridHeight}" Width="953">
                <sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding Path=CustomerName}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Customer Name" IsReadOnly="True" />
                    <sdk:DataGridTextColumn Binding="{Binding Path=Status}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Status" IsReadOnly="True" />
                    <sdk:DataGridTextColumn Binding="{Binding Path=PriceAmt}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Price Amount" IsReadOnly="True"/>

1 个答案:

答案 0 :(得分:3)

您必须使用属性CellStyle

<sdk:DataGrid AutoGenerateColumns="False" ColumnWidth="*" RowDetailsVisibilityMode="Collapsed" x:Name="grdSalesOrder" TabIndex="22" ItemsSource="{Binding Path=PCVSaleOrders}" SelectionMode="Single" Height="{Binding Path=GridHeight}" Width="953">
            <sdk:DataGrid.Columns>
 <sdk:DataGridTextColumn CellStyle="MyStyle" Binding="{Binding Path=CustomerName}" CanUserReorder="True"     CanUserResize="True" CanUserSort="True" Width="Auto" Header="Customer Name" IsReadOnly="True" />
                <sdk:DataGridTextColumn CellStyle="MyStyle" Binding="{Binding Path=Status}"   CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Status" IsReadOnly="True" />
                <sdk:DataGridTextColumn CellStyle="MyStyle" Binding="{Binding Path=PriceAmt}"   CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Price Amount" IsReadOnly="True"/>

你的风格可以像这样设置:

    <Style x:Key="MyStyle" TargetType="sdk:DataGridCell">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Template" Value="{StaticResource DataGridCellTemplate}" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    </Style>

现在您可以选择要更改的内容.. 希望它有所帮助!