Xamarin.Forms CollectionView Introduction
In this article
Download the sample
is a view for presenting lists of data using different layout specifications. It aims to provide a more flexible, and performant alternative to
. For example, the following screenshots show a
CollectionView that uses a two column vertical grid, and which allows multiple selection:
should be used for presenting lists of data that require scrolling or selection. A bindable layout can be used when the data to be displayed doesn't require scrolling or selection. For more information, see
Bindable Layouts in Xamarin.Forms.
is available from Xamarin.Forms 4.3.
CollectionView and ListView differences
APIs are similar, there are some notable differences:
has a flexible layout model, which allows data to be presented vertically or horizontally, in a list or a grid.
supports single and multiple selection.
has no concept of cells. Instead, a data template is used to define the appearance of each item of data in the list.
automatically utilizes the virtualization provided by the underlying native controls.
reduces the API surface of
. Many properties and events from
are not present in
does not include built-in separators.
will throw an exception if its
is updated off the UI thread.
Move from ListView to CollectionView
implementations in existing Xamarin.Forms applications can be migrated to
implementations with the help of the following table:
is populated with data by setting its
ItemsSource property. For more information, see
Populate a CollectionView with data.
The appearance of each item in a
can be defined by setting the
ItemTemplate property to a
. For more information, see
Define item appearance.
has no concept of cells, and therefore no concept of disclosure indicators. Instead, a data template is used to define the appearance of each item of data in the list.
does not include built-in separators. These can be provided, if desired, in the item template.
supports single and multiple selection. For more information, see
Xamarin.Forms CollectionView Selection.
CollectionView, the row height of each item is determined by the
ItemSizingStrategy property. For more information, see
automatically uses the virtualization provided by the underlying native controls.
Headers and footers
can present a header and footer that scroll with the items in the list, via the
FooterTemplate properties. For more information, see
Headers and footers.
displays correctly grouped data by setting its
IsGrouped property to
true. Group headers and group footers can be customized by setting the
GroupFooterTemplate properties to
objects. For more information, see
Xamarin.Forms CollectionView Grouping.
Pull to refresh
Pull to refresh functionality is supported by setting a
as the child of a
RefreshView. For more information, see
Pull to refresh.
Context menu items
Context menu items are supported by setting a
SwipeView as the root view in the
that defines the appearance of each item of data in the
. For more information, see
ScrollTo methods, that scroll items into view. For more information, see