How to do Data Virtualization for online content in windows phone?

人盡茶涼 提交于 2019-12-19 11:06:55

问题


I have an app which gets content from internet. those pieces of information are so large and can't fit in memory.

LongListSelector does UI Virtualization well. remains Data Virtualization. I thought the solution is to save data in database first then show it.

I have no idea how to do it and these are questions in my head:

  • Is that how I should do Data Virtualization?
  • what happens if there is no enough space.
  • any source or tip is appreciated.

thanks.


回答1:


Basic idea of data virtualization is creating custom collection that can load & return item(s) on-demand (without prior loading complete set in memory). Following is radically simplified implementation (adapted from this blog post) :

namespace VirtualizingDataTest
{
  public class VirtualizedDataSource : IList
  { 
    public object this[int index]
    {
      get
      {
        string text = "Requesting\t" + index;

        Debug.WriteLine(text);
        return "Item " + index;
      }
      set
      {
        throw new NotImplementedException();
      }
    }
}

In the sample above, new item created upon requested. In your case, if the online source provide a way to request item in specific index, you don't need database. You can put logic to download specific item in this[] getter. Further references (various better/more complete implementation) can be found here : https://stackoverflow.com/a/6712373/2998271

Given UI virtualization working, LLS will request only sub set of items to be displayed (in other words, this[] getter won't get invoked for all index available, only those to be displayed).



来源:https://stackoverflow.com/questions/22186076/how-to-do-data-virtualization-for-online-content-in-windows-phone

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