I want to be able to center the text in the column and the cell for one column. This is the XAML that I have so far. I cannot figure out how to do it for one item opposed to a
Set the HorizontalContentAlignment
property of the ListViewItem
container to Stretch
and use a CellTemplate
with a TextBlock
for the cell you want to center:
<ListView
Grid.Column="0"
Margin="3,3,0,3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Visible"
SelectionMode="Single">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridView.Columns>
<GridViewColumn Width="100" DisplayMemberBinding="{Binding CopiedFrom}">
<GridViewColumn.Header>
<GridViewColumnHeader>Copied From:</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
<!-- Centered: -->
<GridViewColumn Width="100">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</GridViewColumn.HeaderContainerStyle>
<GridViewColumn.Header>
<GridViewColumnHeader>Date/Time:</GridViewColumnHeader>
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>