Skip to content

TemplateProperty

TemplateProperty is a property used to link elements added as Template on .uxml with the View class.
When declared in a View class, the SourceGenerator collects the declared TemplateProperty.
For more on Template, see here.

How to Declare

As with BindableProperty, you can declare by calling TemplateProperty<T>.Create().
Set <T> as the type of the View you want to specify.

csharp
private static readonly TemplateProperty<CounterTemplate> TemplateViewProperty = TemplateProperty<CounterTemplate>.Create(
    TemplateInfoList.ChildVmTemplate
);

Parameters

TemplateProperty<T>.Create() can specify the following parameters:

ParameterTypeRequiredDefault Value
templateInfoTemplateInfoyes-
  • templateInfo
    Parameter for specifying the Template declared in .uxml.
    Information for Template declared in .uxml is generated by the SourceGenerator as TemplateInfoList. The View specified by templateInfo will receive the ViewModel bound to the class that declared this TemplateProperty<T>.
    If you want to bind a ViewModel, the View class specified by <T> must inherit from HaikaraViewModelProvidableBase.