Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content alignment for Gridviewcolumn in the listview

Please see the picture below enter image description here

Following is the code for this ::

<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>
like image 792
Pankaj Upadhyay Avatar asked Feb 03 '11 06:02

Pankaj Upadhyay


1 Answers

Do you want to center to content for all your cells? In that case you can add HorizontalContentAlignment for ListViewItem

<ListView ...>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
        </Style>
    </ListView.ItemContainerStyle>
    <!--...-->
</ListView>
like image 111
Fredrik Hedblad Avatar answered Sep 20 '22 00:09

Fredrik Hedblad