Incremental, On-Demand Loading with Xamarin.Forms ListView

Incremental, On-Demand Loading with Xamarin.Forms ListView

Here, we'll show you how to use the ComponentOne CollectionView for Xamarin to provide on-demand loading for the Xamarin.Forms ListView control.

On-demand loading is a common technique in mobile apps where data is loaded in chunks as the user scrolls down a list in real time. If you’ve ever searched for something to buy on the Amazon shopping app, then you’ve seen on-demand loading. It’s ideal for mobile apps because downloading data conservatively improves app performance, and users prefer downloading only what they need. In the development world, it’s also known as incremental loading. If you’re developing a mobile app using Xamarin.Forms, you'll find that on-demand loading is not supported for free—you have to implement it yourself.

Here, we'll show you how to use the ComponentOne CollectionView for Xamarin to provide on-demand loading for the Xamarin.Forms ListView control.

How to Perform On-Demand Loading with the Xamarin.Forms ListView

Adding on-demand loading to ListView is accomplished in two basic steps:

  1. Implement your own collection view class that extends a C1CursorCollectionView and overrides GetPageAsync. This is where we'll provide our logic that loads the data in chunks or pages.
  2. Extend ListView and listen to the ItemAppearing event. This determines when the user has reached the bottom of the ListView

Next, let’s cover both steps in more detail.

Extending C1CursorCollectionView

The C1CursorCollectionView is the base class for adding cursor-like, incremental loading to a collection of items. It gets its name from the similarly named paging mechanism used by the Twitter API. It provides the helpful hooks to load data in “real time” as paged chunks. First, add the C1.CollectionView packages to your Xamarin.Forms app.

Right-click your solution and select Manage NuGet Packages for Solution. Then search or browse the list for C1.CollectionView. Click Install.

Incremental, On-Demand Loading with Xamarin.Forms ListView

The C1CollectionView is a portable class library , so it should work across all projects within your Xamarin.Forms solution. It contains multiple types of collection views. Create a new class that extends the C1CursorCollectionView base class. Here's the bare bones implementation of this class and the GetPageAsync method.

**public** **class** MyOnDemandCollectionView : C1CursorCollectionView<MyDataItem>   
    **protected** override async Task<Tuple<string, IReadOnlyList<MyDataItem>>> GetPageAsync(string pageToken, **int**? count = null)   
        // create new page of items   
        var newItems = **new** List<MyDataItem>();   
        **for**(**int** i = 0; i < count; i++)   
            newItems.Add(**new** MyDataItem(**this**.Count + i));   

        **return** **new** Tuple<string, IReadOnlyList<MyDataItem>>("token not used", newItems);   

xamarin.forms mobile .net

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

jQuery Ajax CRUD in ASP.NET Core MVC with Modal Popup

In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.

Learn How to Add App Themes for Xamarin.Forms

Learn how to add dark and light themes to your applications using Xamarin.Forms 4.7 and customize color styles in your app UI.

Watch the Xamarin Podcast: Inverter Converter and Xamarin.Forms 4.7 |

James and Matt will talk about multi-bindings and how using it in the right way will unleast the mysterious beast Inverter Converter.

Blazor for ASP.NET Web Forms Developers PDF

In this blog post, I will share the Free e-book: Blazor for ASP.NET Web Forms Developers PDF. This book is great for ASP.NET Web Forms developers looking for guidelines. As well as strategies for migrating their existing apps to a modern, open-source, and cross-platform web framework.