Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Pull-to-Refresh doesn't stop loading

$
0
0

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;
    }
}~~~~

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>