<DataTemplate>
<TextBlock x:Name="Txt" Text="{Binding fieldA}" />
</DataTemplate>
上記のXAMLと同等のプログラムを実行したいと思います(XAMLにはさらに多くの機能があり、関連するビットのみを示しています)。これまでのところ私は持っています:
DataTemplate newDataTemplate = new DataTemplate();
TextBlock newTextBlock = new TextBlock();
newTextBlock.SetBinding(TextBlock.TextProperty, new Binding("fieldA"));
newTextBlock.Name = "txt";
では、TextBlockをDataTemplateに追加するにはどうすればよいですか。つまり、次のようなことをしたいと思います。
newDataTemplate.children.Add(TextBlock)