Other Virtual Sources
- 2 minutes to read
The How to Use Virtual Sources tutorial demonstrates how to bind to InfiniteAsyncSource. This topic describes other virtual sources’ specificities.
Paged Sources
This section describes how to use the PagedAsyncSource or PagedSource.
Examples:
Specificities:
- You can specify the PagedSourceBase.PageSize property to set the maximum number of rows that can be displayed on a page.
- You can set the PagedSourceBase.PageNavigationMode property to Arbitrary to allow navigating to any page.
To show a total page count:
- Set the PagedSourceBase.PageNavigationMode property to ArbitraryWithTotalPageCount.
- Handle the PagedAsyncSource.GetTotalSummaries (or PagedSource.GetTotalSummaries) event to calculate the Count value.
- Use the PagedAsyncSource.FetchPage (or PagedSource.FetchPage) event to fetch a page.
InfiniteSource/PagedSource
This section describes how to use the InfiniteSource or PagedSource.
In the examples below, a data access object (IssuesContext) emulation is used instead of a web service emulation:
Specificities:
In addition to events demonstrated in the Fetch Data and Enable Scrolling topic, you have to handle the InfiniteSource.CreateSource (or PagedSource.CreateSource) and InfiniteSource.DisposeSource (or PagedSource.DisposeSource) events:
source.CreateSource += (o, e) => { e.Source = new IssuesContext(); }; source.DisposeSource += (o, e) => { var issuesContext = (IssuesContext)e.Source; issuesContext.Dispose(); };
Get the IssuesContext before obtaining rows:
static FetchRowsResult FetchRows(FetchRowsEventArgs e) { // ... var issuesContext = (IssuesContext)e.Source; var issues = issuesContext.GetIssues(page: e.Skip / pageSize, pageSize: pageSize, sortOrder: sortOrder, filter: filter); // ... } static object[] GetTotalSummaries(GetSummariesEventArgs e) { // ... var issuesContext = (IssuesContext)e.Source; var summaryValues = issuesContext.GetSummaries(filter); // ... }
In the InfiniteSource.FetchRows (or PagedSource.FetchPage) handler, return a list of objects separately and specify the FetchRowsEventArgs.HasMoreRows (or FetchPageEventArgs.HasMoreRows) property:
source.FetchRows += (o, e) => { var fetchRowsResult = FetchRows(e); e.Result = fetchRowsResult.Rows; e.HasMoreRows = fetchRowsResult.HasMoreRows; };