Programmatically add a TextBlock to a DataTemplate
<DataTemplate>
<TextBlock x:Name="Txt" Text="{Binding fieldA}" />
</DataTemplate>
I want to make the equivalent of the above XAML programmatically (for XAML more, I just showed the corresponding bits). So far I have received:
DataTemplate newDataTemplate = new DataTemplate();
TextBlock newTextBlock = new TextBlock();
newTextBlock.SetBinding(TextBlock.TextProperty, new Binding("fieldA"));
newTextBlock.Name = "txt";
So, how do I now add a TextBlock to the DataTemplate .. that is, I want to do something like:
newDataTemplate.children.Add(TextBlock)
+3
1 answer