The .NET Multi-platform App UI (.NET MAUI) CollectionView is a view for presenting lists of data using different layout specifications. It aims to provide a more flexible, and performant alternative to ListView.
The following screenshot shows a CollectionView that uses a two-column vertical grid and allows multiple selections:
CollectionView 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 BindableLayout.
CollectionView and ListView differences
- CollectionView has a flexible layout model, which allows data to be presented vertically or horizontally, in a list or a grid.
- CollectionView supports single and multiple selection.
- CollectionView has no concept of cells. Instead, a data template is used to define the appearance of each item of data in the list.
- CollectionView automatically utilizes the virtualization provided by the underlying native controls.
- CollectionView reduces the API surface of ListView. Many properties and events from ListView are not present in CollectionView.
- CollectionView does not include built-in separators.
- CollectionView will throw an exception if its
ItemsSourceis updated off the UI thread.
Move from ListView to CollectionView
||A CollectionView is populated with data by setting its
||The appearance of each item in a CollectionView can be defined by setting the
|Cells||TextCell, ImageCell, ViewCell||CollectionView 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.|
||CollectionView does not include built-in separators. These can be provided, if desired, in the item template.|
||CollectionView supports single and multiple selection. For more information, see Configure CollectionView item selection.|
||In a CollectionView, the row height of each item is determined by the
||CollectionView automatically uses the virtualization provided by the underlying native controls.|
|Headers and footers||
||CollectionView can present a header and footer that scroll with the items in the list, via the
||CollectionView displays correctly grouped data by setting its
|Pull to refresh||
||Pull to refresh functionality is supported by setting a CollectionView 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 DataTemplate that defines the appearance of each item of data in the CollectionView. For more information, see Context menus.|