As the title suggests I'm looking to inject a code behind element into a data template to be rendered at runtime.
Here is the piece of my XAML code I'd like to inject the code behind element into:
<TabControl x:Name="tcDocuments" DockPanel.Dock="Top">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<Button Content="x" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
(INSERT CLASS BELOW'S CONTENT PROPERTY HERE)
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
And here is the class that I will be adding to the TabControl above's Items:
public class DocumentTab
{
public string File { get; set; }
public string Name { get; set; }
public RichTextBox Content { get; set; }
}
Then every time I add a new DocumentTab object to the TabControl's Item list, The RichTextBox property "Content" is inserted into the DataTemplate tag.
I guess the real question here is is this possible?
Cheers.