title: How to merge custom TreeViewItem style and skin?
body: <p>I would like to make my custom TreeViewItem style skinable. I tried to follow tutorials on the matter, but I have problems abstracting from the simple case to the one I have with multiple resource dictionaries in multiple files.</p>
  
  <p>I defined a custom style for my TreeViewItem in the file:</p>
  
  <pre><code>&lt;ResourceDictionary  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="*****namespace omitted******"&gt;
  
      &lt;Style x:Key="GroupedTreeViewItemStyle" TargetType="{x:Type TreeViewItem}"&gt;
  
          &lt;!-- Most of the content omitted, see below as an example of skin reference --&gt;
  
          &lt;ControlTemplate TargetType="{x:Type TreeViewItem}"&gt;
              &lt;ControlTemplate.Triggers&gt;
                  &lt;Trigger Property="IsSelected" Value="true"&gt;
                      &lt;Setter Property="Background" TargetName="Bd" Value="{DynamicResource BackgroundHighlightBrush}"/&gt;
                      &lt;Setter Property="Foreground" Value="{DynamicResource TextHighlightBrush}"/&gt;
                  &lt;/Trigger&gt;
              &lt;/ControlTemplate.Triggers&gt;
          &lt;/ControlTemplate&gt;
      &lt;/Style&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>Then we have our default skin, defining the two brushes we need:</p>
  
  <pre><code>&lt;ResourceDictionary  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="*****namespace omitted*****"&gt;
  
      &lt;!-- Text Color brushes --&gt;
      &lt;SolidColorBrush x:Key="TextHighlightBrush" Color="White"/&gt;
  
  
      &lt;!-- Box Color Brushes --&gt;
      &lt;SolidColorBrush x:Key="BackgroundHighlightBrush" Color="Black"/&gt;
  
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>Lastly I try to add the two resource dictionaries to the tree view item resources like follows:</p>
  
  <pre><code>&lt;TreeView Name="treeView" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"&gt;
      &lt;TreeView.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary&gt;
                      &lt;Style TargetType="TreeViewItem"&gt;
                          &lt;Setter Property="IsExpanded"  Value="{Binding Expanded, Mode=TwoWay}"/&gt;
                      &lt;/Style&gt;
                  &lt;/ResourceDictionary&gt;
                  &lt;ResourceDictionary  Source="../../Skins/Default.xaml"/&gt;
                  &lt;ResourceDictionary  Source="GroupedTreeViewItemStyle.xaml"/&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/TreeView.Resources&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>But none of the resource dictionaries gets applied. Do you know why?</p>
  
  <p>Thanks in advance for your help!</p>