The issue is that TreeViewItem
is actually a wrapper that is used by the TreeView
itself. It needn't (and shouldn't) be part of your DataTemplate
, as what you have now is creating a TreeViewItem
within a TreeViewItem
(the outer one being created by the TreeView
, and the inner one being part of the template).
This is why your style works, as it gets applied to all TreeViewItem
s, both the one that you're declaring (which ends up being meaningless) and the one created by the TreeView
.
What you should do is replace your DataTemplate
with this:
<HierarchicalDataTemplate ItemsSource="{Binding Folders}">
<StackPanel Orientation="Vertical">
<Image Source="{Binding IconSource}"
Width="16" Height="16" Margin="4,0,4,0"
VerticalAlignment="Center" />
<TextBlock Text="{Binding Title}"
VerticalAlignment="Center" />
<HierarchicalDataTemplate>
(Unfortunately I can't test at the moment, but that should at least get you headed in the right direction).
Leave your style as-is to continue binding the property.