8

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>
Pankaj Upadhyay
  • 12,966
  • 24
  • 73
  • 104

1 Answers1

28

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>
Fredrik Hedblad
  • 83,499
  • 23
  • 264
  • 266
  • 12
    what about only one column? "Date" for example? – xavendano Apr 05 '13 at 19:49
  • I'm not sure why I cannot replicate this fix in Snoop (there seems to be a `ContentPresenter` some way down nested in the `ListViewItem` whose `HorizontalAlignment` needs to be `Stretch`, but which is not updated in accordance with the `ListViewItem.HorizontalContentAlignment` property when changing that in Snoop - one time binding there?), but at runtime, this works. – O. R. Mapper Jan 02 '14 at 14:39
  • And how to center only several ones? – SiL3NC3 Apr 03 '19 at 12:49
  • 3
    This is NOT the answer, as long as this code will align content for all columns, and not for individual columns. – Vali Maties Nov 24 '20 at 07:33