An observable implementation of XpCollection and XPPageSelector.
After 15 years, DevExpress has finally made XPO available free-of-charge. If you’re not familiar with XPO, you can learn more about its feature set here. If you’ve used XPO in the past or are familiar with capabilities, you will love this.
As we already know a Xamarin ListView is populated with data using the ItemsSource property, which can accept any collection implementing IEnumerable but if we want the ListView to automatically update as items are added, removed or changed in the underlying list, you’ll need to use an ObservableCollection. Here is where XpoObservableCollection becomes the best friend for all the XPO fans out there.
XpoObservableCollection inherit from an XPCollection so to use, it is exactly as you would use an XPCollection, the only difference is that the XpoObservableCollection refresh the state of ListViews on Xamarin Forms.
XamarinXpoPageSelector takes it a step further by internally implementing XPPageSelector and presenting the XpoObservableCollection as a pageable collection. With this in mind, on the constructor of the XamarinXpoPageSelector you need to pass the following parameters:
SortingCollection sorting = new SortingCollection(); sorting.Add(new SortProperty("Your Property", SortingDirection.Ascending)); XPCollection <Your Class> Collection = new XPCollection <YourClass>(UnitOfWork); Collection.Sorting = sorting; XamarinXpoPageSelector <YourClass> selector = new XamarinXpoPageSelector <YourClass> (Collection,10, XpoObservablePageSelectorBehavior.AppendPage); this.listView.ItemsSource = selector.ObservableData;
- Collection = An instance of XPCollection.
- 10 = Page Size by default.
- XpoObservablePageSelectorBehavior = AppendPage or SinglePage.
Use Append in case you want to add the results of the new page to the collection or Single page to clear the last page results before showing the new page.
And that’s it. The same awesome ObservableRangeCollection (from MVVM Helpers) that adds important methods such as AddRange, RemoveRange, Replace, and ReplaceRange, it is now available in XPO and of course, it is open source so go and take a look behind the curtains.
Until next time. Xpo out!