Articles in this section
Category / Section

How to provide paging support for Xamrin.Forms ListView?

3 mins read

Xamarin.Forms ListView provides support for paging using the SfDataPager control. It can be achieved through loading data dynamically into ItemsSource of SfListView using OnDemandLoading event for the current page by setting SfDataPager.UseOnDemandPaging as ‘True’.

 

By using the SfDataPager.PageSize property, you can define the number of list items to be displayed in each page.

 

XAML

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" 
             xmlns:sfPager="clr-namespace:Syncfusion.SfDataGrid.XForms.DataPager;assembly=Syncfusion.SfDataGrid.XForms"> 
 
    <ContentPage.BindingContext> 
        <local:ListViewGridLayoutViewModel x:Name="viewModel" /> 
    </ContentPage.BindingContext> 
     
  <Grid> 
    <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
        <sfPager:SfDataPager x:Name ="dataPager"  
                             Source="{Binding GalleryInfo}" 
                             Grid.Row="0"            
                             PageSize="4"  
                             HeightRequest ="50" 
                             NumericButtonCount="6" 
                             UseOnDemandPaging="True" 
                             OnDemandLoading="DataPager_OnDemandLoading"/> 
 
     <syncfusion:SfListView x:Name="listView" Grid.Row="1">  
      <syncfusion:SfListView.ItemTemplate> 
        <DataTemplate> 
          <Grid> 
            <Image Source="{Binding Image}" 
                           Aspect="Fill" 
                           HorizontalOptions="FillAndExpand" 
                           VerticalOptions="FillAndExpand" /> 
            <Grid> 
              <Label Text="{Binding ImageTitle}">
              </Label> 
            </Grid> 
          </Grid> 
        </DataTemplate> 
      </syncfusion:SfListView.ItemTemplate> 
    </syncfusion:SfListView> 
  </Grid> 
</ContentPage> 

 

C#

public GridLayoutPage() 
{ 
  InitializeComponent(); 
  viewModel = new ListViewGridLayoutViewModel(); 
} 
 
private void DataPager_OnDemandLoading(object sender, OnDemandLoadingEventArgs args) 
{ 
  var source = viewModel.GalleryInfo.Skip(args.StartIndex).Take(args.PageSize); 
  listView.ItemsSource = source.AsEnumerable(); 
} 

Screenshot:

List of items displayed

 

Click here to download the sample.


Conclusion

I hope you enjoyed learning about how to provide paging support for Xamrin.Forms ListView.

You can refer to our Xamarin.Forms ListView feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied