Initializing bound collections without freezing the UI
.NET MAUI allows you to represent collections using the CollectionView
element. Typically, applications contain many collections, and often data for these collections is loaded on demand when a view is opened. It’s essential to know how to initialize and update bound collections and avoid performance issues.
Getting ready
Start with the project you got after executing the second recipe of this chapter: Implementing auto-generated view model properties. This project is available at https://github.com/PacktPublishing/.NET-MAUI-Cookbook/tree/main/Chapter02/c2-GeneratedViewModels.
The code for this recipe is available at https://github.com/PacktPublishing/.NET-MAUI-Cookbook/tree/main/Chapter02/c2-CollectionInitialization.
How to do it…
Let’s create a collection in the view model and bind it to CollectionView
. Because data for the collection may be loaded from a remote service, we don’t want...