DataTemplateSelector Class

Definition

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
DataTemplateSelector

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.:
The following example shows a basic use:
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 item by calling OnSelectTemplate(Object, BindableObject) and verifying its result.

SetBinding(BindableProperty, BindingBase)

Sets the binding for property.

(Inherited from DataTemplate)
SetValue(BindableProperty, Object)

Sets the value of property.

(Inherited from DataTemplate)

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 self object's targetProperty to a new Binding instance that was created with path.

Applies to