HBSequence / Sequence.Plugins

A library of MvvmCross/Xamarin Plugins and sample applications
26 stars 12 forks source link

how can i clear the observable collection ? #15

Closed PereAlmendro closed 7 years ago

PereAlmendro commented 7 years ago

I need to clear the collection binded to the listView for each time that user search is this possible with your plugin ? or it only works on the first load of the viewmodel ? ViewModel

int page;
ObservableCollection<Search> _results;
        public ObservableCollection<Search> results
        {
            get
            {
                if (_results == null)
                {
                                        // if(page==1) clear de collection
                    _results = _incrementalCollectionFactory.GetCollection(async          (count,pageSize) =>
                    {
                        return await Task.Run(() => search());
                    });
                }
                return _results;
            }
            set
            {
                _results = value;
                RaisePropertyChanged(() => results);
            }
        }
                 public IMvxCommand Search 
        { 
            get 
            { 
                return new MvxCommand(() =>
                {
                    page = 1;
                    RaisePropertyChanged(() => results);
                });
            } 
        }

android.axml

<Sequence.Plugins.InfiniteScroll.Droid.IncrementalListView
            android:smoothScrollbar="true"
            android:scrollingCache="false"
            android:animationCache="false"
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            local:MvxBind="ItemsSource results"
            local:MvxItemTemplate="@layout/listitem" />
PereAlmendro commented 7 years ago

solved, i found a workaround for my solution, but i think it would be an enhancement having the possibility of clearing the collection in order to reinitialize the list with other items without reinitializing the view.