Friday, 23 August 2019

What’s new in CollectionView in Xamarin.Forms 4.2?

Xamarin.Forms 4.2 was released this week, and includes a number of updates to CollectionView. The main updates are outlined below.

Data

CollectionView now supports loading data incrementally as users scroll through items. This enables scenarios such as asynchronously loading a page of data from a web service, as the user scrolls. In addition, the point at which more data is loaded is configurable so that users don’t see blank space, or are stopped from scrolling. For more information, see Load data incrementally.

Layout

It’s no longer necessary to set the layout orientation of a CollectionView, that uses the ListItemsLayout, with the x:Arguments syntax. Instead, the Orientation property can now be set directly on a ListItemsLayout in XAML. For more information, see Horizontal list.

In addition, CollectionView now supports presenting a header and footer that scroll with the items in the list. The header and footer can be strings, views, or DataTemplate objects. For more information, see Headers and footers.

Scrolling

CollectionView now defines a Scrolled event which is fired to indicate that scrolling occured. For more informatoin, see Detect scrolling.

CollectionView also now includes HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties, which represents whether the horizontal or vertical scroll bar is visible. For more informatoin, see Scroll bar visibility.

In addition, CollectionView defines a ItemsUpdatingScrollMode property which represents the scrolling behaviour of the CollectionView when new items are added to it. This allows, for example, the last item to remain in view when new items are added. For more information, see Control scroll position when new items are added.

Grouping

CollectionView now supports displaying grouped data. However, this functionality is currently only available on iOS, and will be added to Android in due course. For more information, see Grouping.