By default, text is centered in the headers of a ListView
(not in the content cells!), I've been struggling to make it left aligned, here's what I've come up with:
<ListView.Resources>
<DataTemplate x:Key="Templ">
<TextBlock HorizontalAlignment="Left" Text="{Binding}"/>
</DataTemplate>
</ListView.Resources>
...
<GridViewColumn HeaderTemplate="{StaticResource Templ}">File</GridViewColumn>
This does seem to be the right place to alter the appearance of the header, since I can change other properties like Margin
, etc., yet it does not respond to the HorizontalAlignment
property! I'm guessing the textbox is sized to content and itself centered, thus making the alignment property redundant.
How can I make the text left aligned ?
Set the HeaderContainerStyle to a style that sets HorizontalContentAlignment to left:
<ListView.Resources>
<DataTemplate x:Key="Templ">
<TextBlock HorizontalAlignment="Left" Text="{Binding}"/>
</DataTemplate>
<Style x:Key="HeaderStyle" TargetType="GridViewColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn HeaderTemplate="{StaticResource Templ}" HeaderContainerStyle="{StaticResource HeaderStyle}">File</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With