Further optimization with XAML
Previously, we talked about some minor changes we can apply to our XAML to improve on the performance. Let's look at how we can apply some performance enhancements on a ListView
. If you have worked with any native ListView
or UITableView
, one of the biggest problems is the memory usage when we have a lot of elements to load whilst we are scrolling (that is, loading an image into each bitmap for every cell).
How do we solve this issue?
We use techniques for caching cells and reusing cells. Since Xamarin.Forms
2.0, they have introduced some new features and enhancements around cell recycling mechanisms and caching strategies on ListViews
. In order to set a caching strategy, we have two options:
RetainElement
: This is the default behavior. It will generate a cell for each item in the list, cell layout will run for each cell creation. We should only be using this method if the cell layout is frequently changing, or if a cell has a large number of bindings.RecycleElement...