Search code examples
listviewxamarinxamarin.formsuwppull-to-refresh

Why doesn’t my Xamarin.Forms UWP’s ListView provide the “pull to scroll” behaviour?


I’m building a Xamarin.Forms UWP application, in which I provide a ListView populated from the code-behind of the page:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage ...>
   <ContentPage.Content>
      <ListView IsPullToRefreshEnabled="True"
                ItemsSource="{Binding Items, Mode=OneWay}"
                IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
                RefreshCommand="{Binding RefreshCommand}"/>
   </ContentPage.Content>
</ContentPage>

The bind works just fine, but the problem is that I don’t understand why I’m not able to pull to refresh the list. The list is just static; I can only scroll up or down using the mouse's wheel or the scrollbar. The code-behind of the page is this:

public partial class MainPage {
   public MainPage() {
      BindingContext = this;
      Items = new ObservableCollection<string> { "Hi", "Hi", "Hi", "Hi", "Hi", "Hi" };
      
      RefreshCommand = new Command(async () => {
                IsRefreshing = true;
                await RefreshData();
                IsRefreshing = false;
      });

      InitializeComponent();
   }

   private bool _isRefreshing = false;
   public bool IsRefreshing {
      get { return _isRefreshing; }
      set {
         _isRefreshing = value;
         OnPropertyChanged(nameof(IsRefreshing));
      }
    }

    public ObservableCollection<string> Items { get; }
    public ICommand RefreshCommand { get; }

    private async Task RefreshData() { /* ... */ }
}

Can you help me spot the problem?


Solution

  • PullToRefresh isn't implemented in the UWP version of ListViewRender.cs . If you search the Xamarin.Forms source for IsPullToRefreshEnabled you'll find it only in the iOS and Android implementations of ListViewRenderer.

    This was discussed in the following bug report with the current recommendation to use RefreshView :

    PullTORefresh is not working for the UWP platform using XamarinForms ListVIew

    Please try the RefreshView instead. Thanks!