Does LongListSelector make Lazy Load for us?

2019-06-13 18:16发布

问题:

I'm on windows phone 8 project, in this project, I use panorama template. In first panorama I show the news in a longlistselector.

First, I was showing 15 news and nothing was a problem for performance. But now I show 50 news and started to make load time longer I think.

My question is, longlistselector make lazy loading for us or should we make something for it like windows stores one. Or I mean, When I scroll bottoms, It gets the small pictures and titles ?

I've reached ItemRealized and UnRealized events. Should I focus on them ?

By the way, I don't use MVVM correctly. I get the data from web api and binds it to controls.

回答1:

You can achieve lazy-loading using the OnItemRealized event, take a look here http://www.damirscorner.com/InfiniteScrollingWithIncrementalLoadingInWindowsPhone8.aspx

private void OnItemRealized(object sender, ItemRealizationEventArgs e)
{
    var longListSelector = sender as LongListSelector;
    if (longListSelector == null)
    {
        return;
    }

    var item = e.Container.Content;
    var items = longListSelector.ItemsSource;
    var index = items.IndexOf(item);

    if (items.Count - index <= 1)
    {
        //ask for more items and add theme here
    }
}