DataTemplateSelector Class
Definition
Selects DataTemplate objects by data type and container.
public abstract class DataTemplateSelector : Xamarin.Forms.DataTemplate
type DataTemplateSelector = class
inherit DataTemplate
- Inheritance
Remarks
Application developers override the OnSelectTemplate(Object, BindableObject) method to return a unique DataTemplate for a data type and parent container combination. Additionally, because the same exact template instance must be returned for a given piece of data across successive calls to SelectTemplate(Object, BindableObject), developers should create and store these DataTemplate in their constructor overrides.
- OnSelectTemplate must not return another DataTemplateSelector, and
- The Android platform is limited to 20 templates per list view.
class MyDataTemplateSelector : DataTemplateSelector
{
public MyDataTemplateSelector ()
{
// Retain instances
this.templateOne = new DataTemplate (typeof (ViewA));
this.templateTwo = new DataTemplate (typeof (ViewB));
}
protected override DataTemplate OnSelectTemplate (object item, BindableObject container)
{
if (item is double)
return this.templateOne;
return this.templateTwo;
}
private readonly DataTemplate templateOne;
private readonly DataTemplate templateTwo;
}
```</div>
Constructors
DataTemplateSelector() |
Creates a new DataTemplateSelector with default values. |
Properties
Bindings |
Gets a dictionary of bindings, indexed by the bound properties. (Inherited from DataTemplate) |
Values |
Returns a dictionary of property values for this DataTemplate, indexed by property. (Inherited from DataTemplate) |
Methods
CreateContent() |
Used by the XAML infrastructure to load data templates and set up the content of the resulting UI. (Inherited from ElementTemplate) |
OnSelectTemplate(Object, BindableObject) |
The developer overrides this method to return a valid data template for the specified |
SelectTemplate(Object, BindableObject) |
Returns a DataTemplate for |
SetBinding(BindableProperty, BindingBase) |
Sets the binding for |
SetValue(BindableProperty, Object) |
Sets the value of |
Explicit Interface Implementations
IDataTemplate.LoadTemplate |
For internal use only. (Inherited from ElementTemplate) |
IDataTemplateController.Id | (Inherited from DataTemplate) |
IDataTemplateController.IdString | (Inherited from DataTemplate) |
Extension Methods
CreateContent(DataTemplate, Object, BindableObject) |
For internal use by the Xamarin.Forms platform. |
SelectDataTemplate(DataTemplate, Object, BindableObject) |
For internal use by the Xamarin.Forms platform. |
SetBinding(DataTemplate, BindableProperty, String) |
Binds the |