I have a TreeView
that presents several different datatypes in a hierarchy. I have multiple HierarchicalDataTemplate
s defined in my UserControl.Resources
, which I use to alter the look of each node depending on its datatype:
<UserControl.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:MyFirstType}" ItemsSource="{Binding Children}">
....
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:MySecondType}" ItemsSource="{Binding Children}">
....
</HierarchicalDataTemplate>
.... etc ....
</UserControl.Resources>
I'd like to have each type of node have a different hover and selected color. However, all of the examples I've found on changing these colors (for example, this question) involve changing a few system-defined resources, like HighlightBrushKey
. Since I don't have access to the TreeViewItem
s being generated by my TreeView
, how do I go about overriding these resource values on a per-item basis?