简体   繁体   中英

WP8 Listbox jumpy when loading more elements

I have been implementing infinite scroll in my app, but when the List loads more elements the ScrollView Scroll position is not in the same place than before.

The auto scroll (which works well):

private void VideosList_ItemRealized(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
    {
        ScrollViewer sv = VideosList.Descendents().OfType<ScrollViewer>().FirstOrDefault();

        if (sv != null && this.isloading == false && sv.VerticalOffset >= (sv.ScrollableHeight - 60))
        {
            this.isloading = true;
            videosList.getMoreVideos(20);
        }
        //videosList.getMoreVideos(5);
    }

The binding

public void videosListUpdateFinished(object sender, EventArgs e)
{
    YTVideoPage.Focus();
    VideosList.ItemsSource = null;
    VideosList.ItemsSource = videosList.ytvideos.data.items;
    this.isloading = false;
}

How I can get the listbox to remain in the same position when changing the binding? I've tried to get VerticalOffset and set it when load but it doesn't work.

I hope you can help me. Thank you.

Why don't you use the new LongListSelector for WP8? This one works quite well for infinite scrolling. There are also examples how to use this like: http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e

Unfortunately, the twitter API has changed and you won't receive any data, but the example code still helped me to figure out how to implement it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM