-
Notifications
You must be signed in to change notification settings - Fork 2
Getting Started
William Cowell edited this page May 16, 2015
·
5 revisions
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>.
- Create a new page
- Add a ListView or GridView control to the page
- Create a virtualised data source that implements IVirtualisedDataSource<T>
- Create an instance of the IncrementalLoadingCollection<T> using your data source
- Bind the ItemsSource property of the ListView or GridView to the collection
- Select File|New|Project... in Visual Studio 2013
- Select Blank App (Windows) from Templates|Visual C#|Store Apps
- Name the project then click OK
- Right click over the Project in Solution Explorer and select Manage NuGet Packages...
- With Online|nuget.org selected, search for IncrementalLoadingCollection
- Select Install to install the package
- Open MainPage.xaml
- Add the following code inside the default Grid
<ListView x:Name="ListView" />
- Right click over the Project in Solution Explorer and select Add|Class
- Name the class GeneratingDataSource.cs
- 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));
}
}
- Open MainPage.xaml.cs
- 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.