I have a TreeView which i build up in code recursively. I would like to change the template of each TreeViewItem so that i can add in images etc. into the header. I have tried setting the ItemTemplate of the TreeView Item by creating a static resource within the XAML
<DataTemplate x:Key="TreeViewItemControlTemplate">
<sdk:TreeViewItem Background="Purple" >
<TextBlock Text="Foo"></TextBlock>
</sdk:TreeViewItem>
</DataTemplate>
and then use it for each node created in code like so
myNode.ItemTemplate = DirectCast(Me.Resources("TreeViewItemControlTemplate"), DataTemplate)
I would assume this would then change the look of the items (in this example, just create a load of empty TreeViewItems with purple backgrounds). Instead, the TreeView just ignores these templates, and draws it as normal.
Any ideas on what i am doing wrong?