向项目添加项目后,LongListSelector滚动问题

时间:2014-03-16 09:19:06

标签: c# xaml windows-phone-8

我在LongListSelector中显示YouTube视频。当该人到达列表的末尾时,我会添加新视频(每次20个),我正在使用从Here开始刷新类。

现在新的视频显示在列表中,但我只能滚动其中的20个。如果我滚动到那个以外,我可以看到列表项,但它会向后滚动一个橡皮筋效果。现在当我点击任何可见的项目时,我被发送到下一页,当我点击后退按钮时,LongListSelector现在显示所有项目没有问题。

以下是代码:

private void GetYoutubePlaylist(string feedXML)
{
    try
    {
        StringReader stringReader = new StringReader(feedXML);
        XmlReader xmlReader = XmlReader.Create(stringReader);
        SyndicationFeed feed = SyndicationFeed.Load(xmlReader);


        YoutubeVideo video = null;

        foreach (SyndicationItem item in feed.Items)
        {
            video = new YoutubeVideo();

            video.YoutubeLink = item.Links[0].Uri;
            string a = video.YoutubeLink.ToString().Remove(0, 31);
            video.Id = a.Substring(0, 11);
            video.Title = item.Title.Text;
            video.PubDate = item.PublishDate.DateTime;

            video.Thumbnail = YouTube.GetThumbnailUri(video.Id, YouTubeThumbnailSize.Small);

            videosList.Add(video);
        }
        if (video != null)
        {
            MainListBox.ItemsSource = videosList;

        }
    }
    catch { }
}

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

经过大量的头部刮擦,我能够做到这一点。我只需要将视频列表指定为MainListBox的ItemSource,我将null指定给ItemSource。工作得很好

这是最终的代码。

private void GetYoutubePlaylist(string feedXML)
        {
         var last = new YoutubeVideo(); //scroll to this item when new items are loaded
        if(videosList.Count > max_results)
            last = videosList[videosList.Count - 11];
        try
        {
            StringReader stringReader = new StringReader(feedXML);
            XmlReader xmlReader = XmlReader.Create(stringReader);
            SyndicationFeed feed = SyndicationFeed.Load(xmlReader);

            YoutubeVideo video;

            foreach (SyndicationItem item in feed.Items)
            {
                video = new YoutubeVideo();

                video.YoutubeLink = item.Links[0].Uri;
                string a = video.YoutubeLink.ToString().Remove(0, 31);
                video.Id = a.Substring(0, 11);
                video.Title = item.Title.Text;
                video.PubDate = item.PublishDate.DateTime;

                video.Thumbnail = YouTube.GetThumbnailUri(video.Id, YouTubeThumbnailSize.Small);

                videosList.Add(video);
            }

            MainListBox.ItemsSource = null;
            MainListBox.ItemsSource = videosList;
            if(last.Id!=null)
            MainListBox.ScrollTo(last as YoutubeVideo);
        }
        catch {            }
    }