The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Listview can't scroll RRS feed

  • Question

  • Hi all,

    My listview has set some prosperities for scrollviewer but if the items are too many, it can't scroll, here are the codes, you can copy to your local environment and test it:

            <ListView x:Name="units" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding Mode=OneWay}" SelectionMode="None" Grid.Row="2" ManipulationDelta="units_ManipulationDelta">
                <ListView.BorderBrush>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#ff0000" Offset="0"/>
                        <GradientStop Color="#FF992A2A" Offset="1"/>
                    </LinearGradientBrush>
                </ListView.BorderBrush>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid Width="500" Height="60">
                           <TextBlock Text="{Binding UnitName}" Foreground="{StaticResource TextControlForeground}" TextWrapping="Wrap" HorizontalAlignment="Left" FontSize="{Binding FontSize, Mode=OneWay, Source={StaticResource listStyle}}" />
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

    Thanks

    Sunday, December 4, 2016 2:54 PM

Answers

  • Make sure that you have not put the ListView inside a StackPanel:

    <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <ListView x:Name="units" ScrollViewer.VerticalScrollMode="Enabled" .... >

    Also make sure that you have not put in a grid row with a height of Auto:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ListView x:Name="units" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionMode="None" Grid.Row="2">
                ...

    If you do any of this, you need to specify an explicit height for the ListView to get a vertical scrollbar since its height is considered to be infinite:

    <ListView x:Name="units" ScrollViewer.VerticalScrollMode="Enabled" Height="100" ... >


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Breeze Liu Monday, December 5, 2016 10:55 AM
    • Marked as answer by William A Wang Tuesday, December 6, 2016 1:57 AM
    Sunday, December 4, 2016 8:27 PM

All replies

  • Hi!

    On the listview properties add a value to MaxHeight.

    It will work.

    If it's good for you, can you mark this answer as answer of your question please?


    SVP utiliser le Marquer comme reponse; sur les reponses qui vous aide car cela permet aux personnes qui peuvent rencontrer le meme probleme que vous, de retrouver rapidement quelle est la reponse qui a resolu leur probleme. De plus, cela encourage aussi la personne qui a repondu a votre question, et de repondre aux suivantes...

    Sunday, December 4, 2016 4:16 PM
  • Make sure that you have not put the ListView inside a StackPanel:

    <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <ListView x:Name="units" ScrollViewer.VerticalScrollMode="Enabled" .... >

    Also make sure that you have not put in a grid row with a height of Auto:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ListView x:Name="units" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionMode="None" Grid.Row="2">
                ...

    If you do any of this, you need to specify an explicit height for the ListView to get a vertical scrollbar since its height is considered to be infinite:

    <ListView x:Name="units" ScrollViewer.VerticalScrollMode="Enabled" Height="100" ... >


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Breeze Liu Monday, December 5, 2016 10:55 AM
    • Marked as answer by William A Wang Tuesday, December 6, 2016 1:57 AM
    Sunday, December 4, 2016 8:27 PM
  • Hi Magnus,

    After I changed the stackpanel to grid and added a maxheight in rowdefination, the scroll worked.

    Thanks both of you

    Tuesday, December 6, 2016 1:58 AM