Step 1: Fetch Data and Enable Scrolling
- 2 minutes to read
In this step, you create a virtual source, fetch rows from the service, and enable scrolling in the GridControl.
To Fetch Data and Enable Scrolling
Add a GridControl with columns that correspond to the Issues Service’s IssueData to your project:
<Grid:GridControl Name="grid" AutoGenerateColumns="False" AllowSorting="False" AllowColumnFiltering="False"> <Grid:GridControl.Columns> <Grid:GridTextColumn FieldName="Subject" /> <Grid:GridTextColumn FieldName="User" /> <Grid:GridDateColumn FieldName="Created" /> <Grid:GridTextColumn FieldName="Votes" /> <Grid:GridTextColumn FieldName="Priority" /> </Grid:GridControl.Columns> </Grid:GridControl>
Initialize a virtual source. Create an InfiniteAsyncSource instance and set the VirtualSourceBase.ElementType property to the type of rows retrieved from the source.
public MainPage() { this.InitializeComponent(); var source = new InfiniteAsyncSource() { ElementType = typeof(IssueData) }; }
Tip
If your service returns untyped objects (for example, a service returns Json which is converted to a dynamic object), specify the VirtualSourceBase.CustomProperties property.
Fetch rows from the data source:
- Handle the InfiniteAsyncSource.FetchRows event.
- Obtain data using the Issues Service’s GetIssuesAsync method.
- Create the FetchRowsResult class object and specify the FetchRowsAsyncEventArgs.Result property.
public MainPage() { // ... source.FetchRows += (o, e) => { e.Result = FetchRowsAsync(e); }; } static async Task<FetchRowsResult> FetchRowsAsync(FetchRowsAsyncEventArgs e) { IssueSortOrder sortOrder = GetIssueSortOrder(e); IssueFilter filter = MakeIssueFilter(e.Filter); const int pageSize = 30; var issues = await IssuesService.GetIssuesAsync( page: e.Skip / pageSize, pageSize: pageSize, sortOrder: sortOrder, filter: filter); return new FetchRowsResult(issues, hasMoreRows: issues.Length == pageSize); } static IssueSortOrder GetIssueSortOrder(FetchRowsAsyncEventArgs e) { return IssueSortOrder.Default; } static IssueFilter MakeIssueFilter(CriteriaOperator filter) { return null; }
Bind the GridControl to the virtual source by assigning the resulting virtual source’s instance to the DataControlBase.ItemsSource property:
public MainPage() { // ... grid.ItemsSource = source; }