In This Article

TypedDataTemplateSelector Class

An Avalonia.Controls.Templates.IDataTemplate implementation that selects an appropriate Avalonia.Controls.Templates.ITypedDataTemplate from its Templates dictionary based on data type, walking up the Type inheritance tree as needed.

public class TypedDataTemplateSelector : IDataTemplate, ITemplate<object?, Control?>
Inheritance:
object object
Implements:
IDataTemplate ITemplate<object, Control>

Remarks

This class if particularly useful when a fallback data template is needed for a null value item in an Avalonia.Controls.ItemsControl, which is not possible within Avalonia.Controls.Templates.DataTemplates.

Constructors

TypedDataTemplateSelector()

Initializes an instance of the class.

public TypedDataTemplateSelector()

Properties

DefaultTemplate

The default Avalonia.Controls.Templates.IDataTemplate that will be used if there is no Type-based match.

public IDataTemplate? DefaultTemplate { get; set; }

Property Value

IDataTemplate

Templates

Gets the collection of available Avalonia.Controls.Templates.ITypedDataTemplate objects, keyed by Avalonia.Controls.Templates.ITypedDataTemplate.DataType.

[Content]
public ObservableCollection<ITypedDataTemplate> Templates { get; }

Property Value

ObservableCollection<ITypedDataTemplate>

Methods

Build(object?)

Creates the control.

public Control? Build(object? param)
Parameter Type Description
param object

The parameter.

Returns

Control:

The created control.

Match(object?)

Checks to see if this data template matches the specified data.

public bool Match(object? data)
Parameter Type Description
data object

The data.

Returns

bool:

True if the data template can build a control for the data, otherwise false.

Inherited Members

Extension Methods