Introduction

Pull to Refresh
Xamarin Forms ListView control has the ability to allow the user to pull down from the top of the ListView to trigger a refresh command. When the user triggers a PullToRefresh the Command will be invoked the Refreshed event.
Prerequisites
- Visual Studio 2017 (Windows or Mac)
Start by creating a new Xamarin.Forms project. You’ll learn more by going through the steps yourself.
Choose the Cross-platform App project under Visual C#-->Cross-platform in the New Project dialog.

Now Select the Blank App and Choose Portable Class Library(PCL).
Subsequently, go to the solution. In there, you get all the files and sources of your project (PCL). Now, select XAML page and double-click to open the MainPage.Xaml page.
You now have a basic Xamarin.Forms app. Click the Play button to try it out.
You now have a basic Xamarin.Forms app. Click the Play button to try it out.
In this step create a simple ListView.
Now, write the following code .

- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:XamarinListView"
- x:Class="XamarinListView.MainPage">
- <ContentPage.Content>
- <StackLayout>
- <Image x:Name="imgBanner"></Image>
- <ListView x:Name="listPlatforms" ></ListView>
- </StackLayout>
- </ContentPage.Content>
- </ContentPage>
Now, add a list item to ListView. and write the following code .
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- namespace XamarinListView
- {
- public partial class MainPage : ContentPage
- {
- List<string> listItems = new List<string>();
- public MainPage()
- {
- InitializeComponent();
- imgBanner.Source = ImageSource.FromResource("XamarinListView.images.banner.png");
- listItems.Add("Xamarin.Forms");
- listItems.Add("Xamarin.Android");
- listItems.Add("Xamarin.iOS");
- listPlatforms.ItemsSource = listItems;
- }
- }
- }
In this step you need to implement the Pull to Refresh in MainPage.Xaml.
IsPullToRefreshEnabled="True"

Now, write the following code .
MainPage.xaml
MainPage.xaml
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:XamarinListView"
- x:Class="XamarinListView.MainPage">
- <ContentPage.Content>
- <StackLayout>
- <Image x:Name="imgBanner"></Image>
- <ListView x:Name="listPlatforms" IsPullToRefreshEnabled="True"></ListView>
- </StackLayout>
- </ContentPage.Content>
- </ContentPage>
- Command RefreshCommand = new Command();
Now, write the code given below.

MainPage.xaml.cs
- listPlatforms.RefreshCommand = new Command(() => {
- //Do your stuff.
- RefreshData();
- listPlatforms.IsRefreshing = false;
- });
Full Code - MainPage.Xaml.cs
MainPage.Xaml.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- namespace XamarinListView {
- public partial class MainPage: ContentPage {
- List < string > listItems = new List < string > ();
- public MainPage() {
- InitializeComponent();
- imgBanner.Source = ImageSource.FromResource("XamarinListView.images.banner.png");
- listItems.Add("Xamarin.Forms");
- listItems.Add("Xamarin.Android");
- listItems.Add("Xamarin.iOS");
- listPlatforms.ItemsSource = listItems;
- listPlatforms.RefreshCommand = new Command(() => {
- //Do your stuff.
- RefreshData();
- listPlatforms.IsRefreshing = false;
- });
- }
- public void RefreshData() {
- listItems.Add("Xamarin Monkeys");
- listPlatforms.ItemsSource = null;
- listPlatforms.ItemsSource = listItems;
- }
- }
- }
Click the Play button to try it out.

I hope you have understood how to use ListView with Pull to Refresh in Xamarin.forms.
Thanks for reading. Please share comments and feedback.

BAT MANPosted May 11, 2021, 10:44 AM
This tutorial helped me in another way
ashish sharmaPosted Jul 20, 2019, 2:36 AM
Hello where i use to Command RefreshCommand = new Command();
Kartik PawarPosted May 17, 2018, 2:57 AM
Nice article... Keep sharing...