列表视图中Gridview列的内容对齐方式

时间:2011-02-03 06:50:50

标签: wpf xaml gridviewcolumn

请参见下图 enter image description here

以下是此::

的代码
<Grid>
                <ListView Style="{StaticResource listViewStyle}" Name="transactionListView" HorizontalAlignment="Stretch" VerticalAlignment="Top" ItemsSource="{Binding}" MouseDoubleClick="transactionListView_MouseDoubleClick" IsSynchronizedWithCurrentItem="True" >
                    <ListView.View>
                        <GridView ColumnHeaderContainerStyle="{StaticResource gridViewHeaderColumnStyle}">
                            <GridView.Columns>
                                <GridViewColumn Width="70" Header="Serial" DisplayMemberBinding="{Binding Path=Serial}" />
                                <GridViewColumn Width="100" Header="Date" DisplayMemberBinding="{Binding Path=Date, StringFormat={}{0:dd-MM-yyyy}}" />
                                <GridViewColumn Width="200" Header="Seller" DisplayMemberBinding="{Binding Path=Seller}" />
                                <GridViewColumn Width="200" Header="Buyer" DisplayMemberBinding="{Binding Path=Buyer}" />
                                <GridViewColumn Width="70" Header="Bales" DisplayMemberBinding="{Binding Path=Bales}" />
                            </GridView.Columns>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>

1 个答案:

答案 0 :(得分:24)

您想要集中注意所有细胞的内容吗?在这种情况下,您可以为HorizontalContentAlignment

添加ListViewItem
<ListView ...>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
        </Style>
    </ListView.ItemContainerStyle>
    <!--...-->
</ListView>