how to clear listview infinite scroll in MessagingCenter xamarin forms

MehdiMllMehdiMll Member ✭✭

constructor :

public ListVM()
            {         
    Items = new InfiniteScrollCollection<ListModel>
                        {
                            OnLoadMore = async () =>
                            {
                                // load the next page
                                var page = Items.Count / PageSize;
                                if ((Items.Count % PageSize) != 0)
                                {
                                    page++;
                                }
                                var accessToken = Settings.AccessToken;

                                var items = await _apiServices.GetListAsync(accessToken, page, PageSize);

                                if (items.Count() == 0)
                                {
                                    IsWorking = false;
                                }
                                // return the items that need to be added
                                return items;
                            }
                        };

          // load the initial data
                Items.LoadMoreAsync();
    }

     public override void OnAppearing()
            {
                base.OnAppearing();
                MessagingCenter.Subscribe<ListView>(this, Settings.MESSAGE_RefreshControlList, async (callback) =>
                {

                    Items.Clear();
                    await Items.LoadMoreAsync();

                });

            }

Answers

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai
    edited May 24

    You can set a property in ViewModel such as

    public bool isNeedLoadMore= true;
    

    Only it equals true that call** LoadMoreAsync()**

    And set it as false in MessagingCenter ,then reset the ItemsSource of listView

Sign In or Register to comment.