Following ListView shall resize its Items, wich are rendered with a TextBlock DataTemplate, by decreasing the FontSize. The initial FontSize is specified in Style and should be the maximum (23pt).
If Item Text get's to long, it is wrapped to a maximum of 2 lines.
When the Window resizes its height or the space for the control gets smaller than needed for displaying the Items, the FontSize shall be reduced untill all Items can be displayed. Formerly wrapped Text shall be "unwrapped" if possible
<ListView x:Name="myListView" Grid.Row="0" Grid.Column="0"
Background="White" BorderBrush="Black" BorderThickness="1"
IsHitTestVisible="False"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock MaxHeight="80"
Margin="0,0,0,21"
Text="{Binding}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="23pt" />
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
<Setter Property="FontFamily" Value="Arial Regular" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Left" />
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
...
</ListView.ItemContainerStyle>
</ListView>
Example Picture showing what i want
I already tried to achieve the requirement by using a ViewBox around the ListView, but this will resize height and width as well (ratio) ==> But the Available width for the text shall be constant.
Another way was to override MeasureOverride for ListView to decrease FontSize, if desired size of the listView > available size for the control. But this didn't work neither.
Maybe some clever guy can help me with this problem.
Best Regards,
EDIT 17.08.2017
I missed some necessary information. The ListView is inside a grid at row = 0 , column = 0:
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
The GridCell 0,0 can only resize in height. The ListView shall take the whole Cellsize and adjust the FontSize of its children to fit in (with the max FontSize avalaible for that). Wrapping of the Text to max 2 textlines is also important.