I want to create a style for my ListViews in my WPF app, which makes them appear more like the Windows Explorer ListView. The thing I am stuck on is the ellipsis (...) that appears in the Grid/Details view when a column is too narrow to fix the text.
I know I can override the cell template of each column, and explicitly set the TextTrimming
mode to get ellipsis on a per-column basis. However, I want a style that I can apply to any ListView to get the same behavior.
I want to be able to define the listview like this:
<ListView ItemsSource="{Binding Library}" Style="{StaticResource ExplorerListStyle}">
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Title" DisplayMemberBinding="{Binding Title}" />
<GridViewColumn Width="60" Header="Author" DisplayMemberBinding="{Binding Author}" />
</GridView>
</ListView.View>
</ListView>
I also want to be able to override the cell template for some columns, e.g. to set the text color, ideally while still inheriting the TextTrimming
mode for the text in the template.
The only way I have managed to achieve this so far is to explicitly override the TextBlock style inside the ListView:
<ListView ItemsSource="{Binding Library}">
<ListView.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Width="90" Header="Title" DisplayMemberBinding="{Binding Title}" />
<GridViewColumn Width="60" Header="Author" DisplayMemberBinding="{Binding Author}" />
</GridView>
</ListView.View>
</ListView>
However, this seems a bit heavy handed, and it's not possible, as far as I can tell, to set this in a style.
So, I'm looking for another way to set the TextTrimming mode for a GridViewColumn
s header and cells, that can be set in a style, and doesn't require explicit CellTemplate
s.
Thanks,
Mark