UWP ListView not scrolling vertically

Apptacular Apps 386 Reputation points

After adding a ListView inside a Grid, it doesn't scroll vertically for some reason. I've placed the ListView inside a ScrollViewer then taken it out again and that still didn't make a difference. What needs to be done to fix this and add a vertical scroll bar so the user is aware that all content can't fit their screen? Should anything else be change to ensure best performance?

        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    <StackPanel Grid.Row="0">
        <TextBlock x:Uid="Header" Style="{StaticResource HeaderTextBlockStyle}" />
        <TextBlock Text="SubHeader" Style="{StaticResource SubheaderTextBlockStyle}"/>
    <ListView Grid.Row="1"
                ItemsSource="{x:Bind listItems}"
                    <TextBlock Text="{Binding Title}" 
                        Style="{StaticResource TitleTextBlockStyle}" />
Universal Windows Platform (UWP)
{count} vote

Accepted answer
  1. Matt Lacey 791 Reputation points MVP

    This issue is that your (second) RowDefinition is set to Auto.

    This means it will grow as big as the contents. Unfortunately, there's nothing anywhere to then prevent the ListView from growing indefinitely to host all the items it contains. As the ListView then becomes as big as all the items it contains, it never needs to show the scrollbar. Yes, this happens even though the listview (and the grid's second row) grows past the bottom of the window.
    The easiest way to address this is to force the row to be limited to not extend beyond the visible window space.
    If you set the height of the second RowDefinition to be a star (see below) which will tell the row to take up all the available space (in the window) but no more. In turn, this limits the space available to the ListView and that then will cause the scrollbar to show once there are sufficient items in the list that scrolling becomes necessary.

             <RowDefinition Height="Auto"/>
             <RowDefinition Height="*"/>
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Xiaodi Yan 876 Reputation points MVP

    Hi, try to update the layout like this:

    <Grid VerticalAlignment="Stretch">
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    ...your StackPanel...
    <ListView Grid.Row="1" VerticalAlignment="Stretch" >