View Caching Strategy Enum
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Enumerates caching strategies for a ListView.
This enumeration supports a bitwise combination of its member values.
[System.Flags] public enum ListViewCachingStrategy
type ListViewCachingStrategy =
Indicates that unneeded cells will have their binding contexts updated to that of a cell that is needed.
Indicates that for every item in the List View's ItemsSource property, a single unique element will be constructed from the DataTemplate.
Application developers can specify one of these values when constructing a ListView to determine whether the List View will minimize their memory footprint and speed execution by recycling list cells, or will instead generate a cell for every item in the list. Currently, the default behavior is to retain item data in their generated cells when they are not needed. (Items are not needed, for example, when they are far enough off screen that their display is not imminent.) This behavior corresponds to a value of RetainElement. For performance reasons, it is likely that the default behavior will be changed to RecycleElement in a future release. In the meantime, for memory and performance reasons, app developers should specify RecycleElement when constructing a new List View.
The performance advantage of RecycleElement is so great that application developers have been provided with a XAML syntax shortcut for initializing List Views. Instead of
x:TypeArguments syntax that specifies a parameter for the ListView(ListViewCachingStrategy) constructor, XAML for Xamarin.Forms provides a XAML attribute for a non-existent property that corresponds to the caching strategy argument of the constructor. Application developers can set the
CachingStrategy attribute to either of the
RecycleElement (preferred) or
RetainElement values to choose a caching strategy. For example:
<ListView CachingStrategy="RecycleElement" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <!-- ... --> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>