Creating Data Templates in Code
Avalonia also supports creating data templates in code with the FuncDataTemplate<T> class.
At its simplest you can create a data template by passing a lambda which accepts an instance to the FuncDataTemplate<T> constructor:
1
var template = new FuncDataTemplate<Student>(x =>
2
new TextBlock
3
{
4
[!TextBlock.TextProperty] = new Binding("FirstName"),
5
});
Copied!
Is equivalent to:
1
<DataTemplate DataType="{x:Type local:Student}">
2
<TextBlock Text="{Binding FirstName}"/>
3
</DataTemplate>
Copied!
Last modified 1mo ago
Export as PDF
Copy link