Skip to content

Getting Started

William Cowell edited this page May 16, 2015 · 5 revisions

Overview

Using the IncrementalLoadingCollection<T> is easy. You can use it in place of an ObservableCollection<T> as an ItemsSource for a ListView or GridView control in any Windows Universal app.

To use the IncrementalLoadingCollection<T> you must provide the class with a data source that is capable of loading data sequentially by implementing the IVirtualisedDataSource<T>.

  1. Create a new page
  2. Add a ListView or GridView control to the page
  3. Create a virtualised data source that implements IVirtualisedDataSource<T>
  4. Create an instance of the IncrementalLoadingCollection<T> using your data source
  5. Bind the ItemsSource property of the ListView or GridView to the collection

Walkthrough

  1. Select File|New|Project... in Visual Studio 2013
  2. Select Blank App (Windows) from Templates|Visual C#|Store Apps
  3. Name the project then click OK
  4. Right click over the Project in Solution Explorer and select Manage NuGet Packages...
  5. With Online|nuget.org selected, search for IncrementalLoadingCollection
  6. Select Install to install the package
  7. Open MainPage.xaml
  8. Add the following code inside the default Grid

<ListView x:Name="ListView" />

  1. Right click over the Project in Solution Explorer and select Add|Class
  2. Name the class GeneratingDataSource.cs
  3. Add the following code into the file:

public class GeneratingDataSource : IVirtualisedDataSource<int>
{
    private readonly int _count;

    public GeneratingDataSource(int count = 1000000)
    {
        _count = count;
    }

    public Task<int> GetCountAsync()
    {
        return Task.FromResult(_count);
    }

    public Task<IEnumerable<int>> GetItemsAsync(uint startIndex, uint count)
    {
        return Task.FromResult(Enumerable.Range((int)startIndex, (int)count));
    }
}

  1. Open MainPage.xaml.cs
  2. Add the following code after the this.Initialize();

var dataSource = new GeneratingDataSource();
var collection = new IncrementalLoadingCollection<int>(dataSource);
ListView.ItemsSource = collection;

Note that the IncrementalLoadingCollection is implemented as a Portable Class Library for Universal apps, so you can use it in apps targeting Windows, Windows Phone, or Universal apps.

Clone this wiki locally