locked
How to scroll a ListView programmatically

    Question

  • I have created a ListView with footer in my window phone application. How can I programmatically scroll the ListView so that the footer is visible?

    Thank you.

    Wednesday, October 29, 2014 5:33 AM

Answers

  • Hi Shah,

    Please don't do like this, Listview has its inner ScrollViewer, therefore system has a ScrollIntoView method. If we add a scrollview as a container, it may eat some gesture that would apply to ListView and it's kind of duplicate.

    @windevvic, you could do something like this:

    XAML:

            <ListView x:Name="lsv" HorizontalAlignment="Left" Height="378" 
                      Margin="139,122,0,0" VerticalAlignment="Top" Width="166"
                      Footer="This part is footer">
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
            </ListView>
            <Button Content="Button" HorizontalAlignment="Left" Height="80" Margin="443,191,0,0" VerticalAlignment="Top" Width="172" Click="Button_Click"/>

    CS:

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                lsv.ScrollIntoView(lsv.Footer);
            }

    It's done.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Thursday, November 06, 2014 1:45 AM
    Moderator

All replies

  • Hi put your listview in scrollview and try this code
     list.SelectedIndex = //your index
                            list.SelectedItem = //perticular item you want to select
                            list.UpdateLayout();
                            list.ScrollIntoView('perticular item you want to select');
                            list.Focus();
                            int NumberOffset = count * 70;
                            Content.UpdateLayout();
                            Content.ScrollToVerticalOffset(NumberOffset);
                            myScrollviewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;


    shah

    Wednesday, October 29, 2014 6:11 AM
  • But I am not trying to scroll to a list item in a list view. I am trying to scroll to the list footer.

    list.SelectedItem = //perticular item you want to select

    what should I set the above code to?

    Wednesday, October 29, 2014 5:01 PM
  • can you plz share your xaml code. 

    And can you plz try this code also I hope so its may be work I am not sure but plz try

    list.SelectedIndex = //your last item index list.SelectedItem = //romove this line

    //after this all code are same


    shah

    Thursday, October 30, 2014 4:18 AM
  • Hi Shah,

    Please don't do like this, Listview has its inner ScrollViewer, therefore system has a ScrollIntoView method. If we add a scrollview as a container, it may eat some gesture that would apply to ListView and it's kind of duplicate.

    @windevvic, you could do something like this:

    XAML:

            <ListView x:Name="lsv" HorizontalAlignment="Left" Height="378" 
                      Margin="139,122,0,0" VerticalAlignment="Top" Width="166"
                      Footer="This part is footer">
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
                <x:String>asdsadasdasda</x:String>
            </ListView>
            <Button Content="Button" HorizontalAlignment="Left" Height="80" Margin="443,191,0,0" VerticalAlignment="Top" Width="172" Click="Button_Click"/>

    CS:

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                lsv.ScrollIntoView(lsv.Footer);
            }

    It's done.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Thursday, November 06, 2014 1:45 AM
    Moderator