Introduction
This blog gives an illustration for adding item controls to tree view at run
time, here my tree view name is filterableTreeview. to add item template into
tree view i have taken of two classes
- FrameworkElementFactory : fore create
data template
- Binding : helps to bind value with
template
- DataTemplate : Helps to bind value with
template
See the bellow code your will get some ideas.
FrameworkElementFactory FEF =
new FrameworkElementFactory(typeof(Label));
Binding CBG =
new Binding("object
to bind");
FEF.SetValue(Label.ContentProperty, CBG);
FEF.SetValue(Label.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
FEF.SetValue(Label.VerticalAlignmentProperty, VerticalAlignment.Stretch);
DataTemplate IT =
new DataTemplate();
IT.VisualTree = FEF;
this.filterableTreeview.ItemTemplate
= IT;