DataTemplateSelector Class
Definition
Important
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.
Selects DataTemplate objects by data type and container.
public ref class DataTemplateSelector abstract : Microsoft::Maui::Controls::DataTemplate
public abstract class DataTemplateSelector : Microsoft.Maui.Controls.DataTemplate
type DataTemplateSelector = class
inherit DataTemplate
Public MustInherit Class DataTemplateSelector
Inherits 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.
Developers should note the following items:
- 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;
}
Constructors
DataTemplateSelector() |
Properties
Bindings |
Gets a dictionary of bindings, indexed by the bound properties. (Inherited from DataTemplate) |
LoadTemplate | (Inherited from ElementTemplate) |
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) | |
SelectTemplate(Object, BindableObject) |
Returns a DataTemplate for |
SetBinding(BindableProperty, BindingBase) |
Sets the binding for |
SetValue(BindableProperty, Object) |
Sets the value of |
Explicit Interface Implementations
IDataTemplateController.Id | (Inherited from DataTemplate) |
IDataTemplateController.IdString | (Inherited from DataTemplate) |
Extension Methods
CreateContent(DataTemplate, Object, BindableObject) |
For internal use by the Microsoft.Maui.Controls platform. |
SelectDataTemplate(DataTemplate, Object, BindableObject) |
For internal use by the Microsoft.Maui.Controls platform. |
SetBinding(DataTemplate, BindableProperty, String) |
Binds the |