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
- Derived:
- ImageDataTemplateSelector
- 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.
TryGetTemplateForObject(object?, out IDataTemplate?, out object?)
Tries to resolve an Avalonia.Controls.Templates.IDataTemplate for use with the given data
.
protected virtual bool TryGetTemplateForObject(object? data, out IDataTemplate? template, out object? buildParameter)
Parameter | Type | Description |
---|---|---|
data | object | The data to example. |
template | IDataTemplate | When successful, outputs the Avalonia.Controls.Templates.IDataTemplate to be used. |
buildParameter | object | When successful, outputs the object to be passed when building the template. This object can also replace the default data context of the templated content. |
Returns
- bool:
true
if the template was resolved and output through thetemplate
parameter; otherwisefalse
.
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()