asitis
asitis

Reputation: 3031

Loading Data when the User Scrolls to the End of a List in Windows Phone stops after 5 or 6 scrolls

I am developing a Windows Phone 8.1 application where I have a list page with a ton of data items.

So I decided to implement incremental loading on ListBox. And fortunately I got a solution on it from Danial vaugan's Loading Data when the User Scrolls to the End of a List in Windows Phone 7 sample

And it works well with scrolling. But noticed that after 5 or 6 incremental loading, the Scrollviewer offset change is not working. Since then the concept is not working.

Here is my sample of the Daniel Vaughan's sample project where it loads only 79 items. After that the scroll change is not working.

Is there any limitation to ScrollViewer to prevent it's offset from changing after certain value? But I don't think so because I loaded more than 1000 items at once and it smoothly scrolls till the end.

How to resolve this issue?

Upvotes: 0

Views: 279

Answers (2)

asitis
asitis

Reputation: 3031

Atlast found an alternative way to get the solution. Used Longlist Selector control for incremental list loading. It works as expected.

Reference:

TwitterSearch - Windows Phone 8 LongListSelector Infinite Scrolling Sample

Upvotes: 0

Vivek Maskara
Vivek Maskara

Reputation: 1092

Here's a simple implementation without using MVVM. The idea is to get the ListView's ScrollViewer.

public static ScrollViewer GetScrollViewer(DependencyObject depObj)
{
    if (depObj is ScrollViewer) return depObj as ScrollViewer;

    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
    {
        var child = VisualTreeHelper.GetChild(depObj, i);

        var result = GetScrollViewer(child);
        if (result != null) return result;
    }
    return null;
}

You will need to add a event handler for onLoaded.

ScrollViewer viewer = GetScrollViewer(this.storylist);
    viewer.ViewChanged += MainPage_ViewChanged;

And the MainPage_ViewChanged event handler as.

private async void MainPage_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    ScrollViewer view = (ScrollViewer)sender;
    double progress = view.VerticalOffset / view.ScrollableHeight;
    System.Diagnostics.Debug.WriteLine(progress);
    if (progress > 0.7 & !incall && !endoflist)
    {
        incall = true;
        fetchCountries(++offset);
    }
}

Here's a step by step tutorial.

This isn't neat as it doesn't follow MVVM pattern. Luckily WP 8.1 supports ISupportIncrementalLoading which can be implemented as described in this article.

Upvotes: 1

Related Questions