Coverflow with Out of Memory

老子叫甜甜 提交于 2019-12-02 08:54:45

This is going to be really from the top of my head. Haven't dealt with this in a while.

1.Write yourself a function which will return you a bunch of items

public List<Item> GetFirstItems()
{
    return items.Collection.Take(50);
}

public Item GetOtherItems(int skip)
{ 
     return items.Collection.Skip(skip).Take(25)
}

2.Hook up to the SelectionChangedEvent for your control

//keep this somewhere so you know where you are in the list
var currentBatch = 0;

private void SelectionChanged(sender object, ChangedEventArgs e)
{
     var position = e.CurrentItemIndex % 25;

     if(position > currentBatch)
     {
          currentBatch = position;
          var newItems = GetOtherItems(currentBatch * 25);

          //take the global list of items and modify it;
          //because we are moving right we only need the last 25 so we
          //can skip the first 25
          coverflow= coverflow.Skip(25);

          //add your new items
          coverflow.AddRange(newItems);
          CarouselList.ItemsSource = coverflow; // you will have to clear the source first
     }
     else if(position < currentBatch)
     {
          currentBatch = position;
          var newItems = GetOtherItems(currentBatch * 25);

          //take the global list of items and modify it;
          //because we are moving left we only need the first 25 so we
          //can take the first 25
          coverflow= coverflow.Take(25);

          //add your new items
          newItems.AddRange(coverflow);
          coverflow = newItems;
          CarouselList.ItemsSource = coverflow; // you will have to clear the source first
     }
}

One more thing you will have to take care of is memorizing which was the current item and setting it again to be the current item.

This is all written from the top of my head and I have no idea if it work with your control but I hope it will at least help you a bit :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!