Pull-to-Refresh doesn't stop loading

AbhumMumbhauAbhumMumbhau USMember ✭✭
edited August 2017 in Xamarin.Forms

Hi, I'm using the official Xamarin.Forms pull-to-refresh: video here

All works great! But the loading won't stop! By debug, I can see all bindings working and also RefreshMethod invocation.

CODE:

    public class NotificationViewModel : INotifyPropertyChanged
    {
    private List<Notification> _notificationsList;
    private INotificationService _notificationService;
    private bool _isRefreshing = false;
    private Command _refreshCommand;

    public event PropertyChangedEventHandler PropertyChanged;

    // constructor
    public NotificationViewModel()
    {
        _notificationService = DependencyService.Get<INotificationService>();
        _refreshCommand = new Command(refreshNotification);

        // change me

        //Since we are going to do UI changes we should do it on the UI Thread!
        Device.BeginInvokeOnMainThread(() =>
        {
            loadNotifications();
        });
    }


    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }


    // isRefreshing property for Pull-to-Refresh
    public bool isRefreshing
    {
        get { return _isRefreshing; }
        set
        {
            _isRefreshing = value;
            OnPropertyChanged(nameof(isRefreshing));
        }
    }


    // NotificationList property to the external view
    public List<Notification> notificationsList
    {
        get { return _notificationsList; }
        set
        {
            _notificationsList = value;
            OnPropertyChanged(nameof(notificationsList));
        }
    }


    // refreshCommand property for Pull-to-Refresh
    public Command refreshCommand
    {
        get { return _refreshCommand; }
    }


    // load notifications from the service
    public List<Notification> loadNotifications()
    {
        _notificationsList = _notificationService.fakeNotification(20);
        return _notificationsList;
    }


    // private methods

    // retrieve the notifications
    private void refreshNotification()
    {
        isRefreshing = true;
        _notificationsList = loadNotifications();
        isRefreshing = false;
    }
}~~~~

Best Answer

  • AbhumMumbhauAbhumMumbhau US ✭✭
    Accepted Answer

    Ok, I forgotten the bindings between the listView and the list of items.

            _List.SetBinding(ListView.ItemsSourceProperty, nameof(_ViewModel.notificationsList));
    

    Hope this can help.

Answers

  • AbhumMumbhauAbhumMumbhau USMember ✭✭
    Accepted Answer

    Ok, I forgotten the bindings between the listView and the list of items.

            _List.SetBinding(ListView.ItemsSourceProperty, nameof(_ViewModel.notificationsList));
    

    Hope this can help.

Sign In or Register to comment.