I'm trying to have a design with a top row of fixed height, and a ListView that fills all available remaining space.
The ListView has a large ItemsSource and to properly use UI virtualization, I read that the height needs to be specified. If I set it to an absolute value, it works fine. However, setting it to "Stretch" seems to render the entire ListView (even off screen).
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="200"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<ScrollViewer VerticalScrollMode="Enabled" Grid.Row="1">
<ListView VerticalAlignment="Stretch"/>
</ScrollViewer>
</Grid>
How can I make the ListView take all available space while not going off screen?
The entire ListView is rendered because you have put it inside a ScrollViewer. A standalone ScrollViewer doesn't know anything about virtualization, and basically tells its content that they have infinite space on which to render themselves.
So remove the ScrollViewer, letting the ListView be the Grid's direct child. The ListView has its own internal ScrollViewer that does handle virtualization, which you should see when the ListView gets enough items to fill the screen.
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="200"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<ListView VerticalAlignment="Stretch" Grid.Row="1" />
</Grid>
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