Creating Data Templates in Code
At its simplest you can create a data template by passing a lambda which accepts an instance to the
FuncDataTemplate<T>
constructor:var template = new FuncDataTemplate<Student>((value, namescope) =>
new TextBlock
{
[!TextBlock.TextProperty] = new Binding("FirstName"),
});
Is equivalent to:
<DataTemplate DataType="{x:Type local:Student}">
<TextBlock Text="{Binding FirstName}"/>
</DataTemplate>
Last modified 4mo ago