Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/syncfusionexamples/xamarin.forms-listview-paging

Example showcases how to do paging in Xamarin.Forms Listview using DataPager.
https://github.com/syncfusionexamples/xamarin.forms-listview-paging

datapager listview paging sflistview xamarin xamarin-android xamarin-forms xamarin-ios xamarin-listview xamarin-uwp

Last synced: 7 days ago
JSON representation

Example showcases how to do paging in Xamarin.Forms Listview using DataPager.

Awesome Lists containing this project

README

        

# Paging in Xamarin.Forms Listview

The SfListView allows displaying paging using the [SfDataPager](http://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfDataGrid.XForms~Syncfusion.SfDataGrid.XForms.DataPager_namespace.html) control. It can be performed through loading data dynamically into ItemsSource of the SfListView using OnDemandLoading event for the current page by setting the [SfDataPager.UseOnDemandPaging](http://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfDataGrid.XForms~Syncfusion.SfDataGrid.XForms.DataPager.SfDataPager~UseOnDemandPaging.html) to `True`. By using the [SfDataPager.PageSize](http://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfDataGrid.XForms~Syncfusion.SfDataGrid.XForms.DataPager.SfDataPager~PageSize.html) property, you can define the number of list items to be displayed in each page.

```






















```

```
public class SfListViewPagingBehavior : Behavior
{

private Syncfusion.ListView.XForms.SfListView listView;
private PagingViewModel PagingViewModel;
private SfDataPager dataPager;

protected override void OnAttachedTo(ContentPage bindable)
{
listView = bindable.FindByName("listView");
dataPager = bindable.FindByName("dataPager");
PagingViewModel = new PagingViewModel();
listView.BindingContext = PagingViewModel;
dataPager.Source = PagingViewModel.pagingProducts;
dataPager.OnDemandLoading += DataPager_OnDemandLoading;
base.OnAttachedTo(bindable);
}

private void DataPager_OnDemandLoading(object sender, OnDemandLoadingEventArgs e)
{
var source = PagingViewModel.pagingProducts.Skip(e.StartIndex).Take(e.PageSize);
listView.ItemsSource = source.AsEnumerable();
}

protected override void OnDetachingFrom(ContentPage bindable)
{
listView = null;
PagingViewModel = null;
dataPager = null;
base.OnDetachingFrom(bindable);
}
}
```
To know more about MVVM in ListView, please refer our documentation [here](https://help.syncfusion.com/xamarin/sflistview/mvvm)