Binding to collections
In the previous section, we introduced some basic knowledge of data binding, and we also replaced the model using PassXYZLib. When we introduced data binding, we used ItemDetailPage
and ItemDetailViewModel
to explain how to bind the source property to the target property. For the item detail page, we created data binding from one source to one target. However, there are many cases in which we need to bind a data collection to the UI, such as ListView
or CollectionView
, to display a group of data.
Figure 4.8: Binding to collections
As we can see in Figure 4.8, when we create a data binding from a collection object to a collection view, the ItemsSource
property is the one to use. In .NET MAUI, collection views such as ListView
and CollectionView
can be used and both have an ItemsSource
property.
For the collection object, we can use any collection that implements the IEnumerable
interface. However, the changes to the collection...