I'm trying to create a new TreeViewItem with a control in it like:
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel>
<Button/>
</StackPanel>
<TreeViewItem.Header>
<TreeViewItem>
Except, I'd like to do it at runtime (I'm using C#), but I can't work out how to do this. Can you help?
This is my code that I'm using to generate the node. Somewhere in here I would like to insert a numeric up/down control. I don't have that control yet, but for arguement's sake, let's say that I want to insert a button.
private void TreeView_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if (TreeView.SelectedNode != null)
{
if (((vcvscompiler.DataTypes.dataObjectv)(TreeView.SelectedNode.Tag))._vcardName.re == "adr_work")
{
foreach (string k in ((vcvscompiler.DataTypes.dataObjectv)(TreeView.SelectedNode.Tag))._prefs)
{
TreeViewItem newChild = new TreeViewItem();
newChild.Header = k;
treeView1.Items.Add(newChild);
}
}
}
}
WPF:
<Window.Resources>
<DataTemplate x:Key="myTaskTemplate">
<StackPanel>
<Button content="This is a button!" />
</StackPanel>
</DataTemplate>
</Window.Resources>