title: Setting up WPF treeview triggers to show different images on expand
body: <p>I have a wpf tree view that displays nodes of various types with corresponding images such as folder images.  Initially, the tree and its nodes with corresponding images display as expected.  However when a node is expanded, the expectation is that the image for the expanded node should swap to an expanded image.  I'm trying to use <code>HierarchicalDataTemplate</code> triggers to set this up.</p>
  
  <p><strong>Should the triggers be set up differently?</strong></p>
  
  <p>The tree looks something like:</p>
  
  <pre><code>(Folder Image) Solutions (SolutionsViewModel)
  --(Solution Image) Solution 1 (Solution)
  --(Solution Image) Solution 2 (Solution)
  (Folder Image) Conventions (ConventionsViewModel)
  </code></pre>
  
  <p>The xaml of the main nodes in the tree view (the theme is empty):</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="../Theme.xaml" /&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
  
          &lt;HierarchicalDataTemplate DataType="{x:Type vm:SolutionsViewModel}" ItemsSource="{Binding Items}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Image x:Name="nodeImg" Width="16" Height="16" Source="pack://siteOfOrigin:,,,/Resources/FolderClosed.bmp"/&gt;
                  &lt;TextBlock Margin="5,0,0,0" Text="{Binding Name}" /&gt;
              &lt;/StackPanel&gt;
              &lt;HierarchicalDataTemplate.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding IsExpanded}" Value="True"&gt;
                      &lt;Setter TargetName="nodeImg" Property="Source" Value="pack://siteOfOrigin:,,,/Resources//FolderOpen.bmp"/&gt;
                  &lt;/DataTrigger&gt;
              &lt;/HierarchicalDataTemplate.Triggers&gt;
          &lt;/HierarchicalDataTemplate&gt;
  
          &lt;HierarchicalDataTemplate DataType="{x:Type sol:Solution}" ItemsSource="{Binding Items}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Image x:Name="treeImg" Width="16" Height="16" Source="pack://siteOfOrigin:,,,/Resources/SolutionClosed.bmp"/&gt;
                  &lt;TextBlock Margin="5,0,0,0" Text="{Binding Name}" /&gt;
              &lt;/StackPanel&gt;
              &lt;HierarchicalDataTemplate.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding IsExpanded}" Value="True"&gt;
                      &lt;Setter TargetName="treeImg" Property="Source" Value="pack://siteOfOrigin:,,,/Resources//SolutionOpen.bmp"/&gt;
                  &lt;/DataTrigger&gt;
              &lt;/HierarchicalDataTemplate.Triggers&gt;
          &lt;/HierarchicalDataTemplate&gt;
  
          &lt;HierarchicalDataTemplate DataType="{x:Type vm:ConventionsViewModel}" ItemsSource="{Binding Items}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Image x:Name="nodeImg" Width="16" Height="16" Source="pack://siteOfOrigin:,,,/Resources/FolderClosed.bmp"/&gt;
                  &lt;TextBlock Margin="5,0,0,0" Text="{Binding Name}" /&gt;
              &lt;/StackPanel&gt;
              &lt;HierarchicalDataTemplate.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding IsExpanded}" Value="True"&gt;
                      &lt;Setter TargetName="nodeImg" Property="Source" Value="pack://siteOfOrigin:,,,/Resources//FolderOpen.bmp"/&gt;
                  &lt;/DataTrigger&gt;
              &lt;/HierarchicalDataTemplate.Triggers&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/UserControl.Resources&gt;
  &lt;UserControl.DataContext&gt;
      &lt;ObjectDataProvider 
      ObjectType="{x:Type vm:TreeViewModel}"
      MethodName="CreateDefaultTree"
      /&gt;
  &lt;/UserControl.DataContext&gt;
  &lt;ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"&gt;
      &lt;Grid&gt;
          &lt;TreeView Name="solutionsModel" ItemsSource="{Binding Items}"&gt;
              &lt;TreeView.ItemContainerStyle&gt;
                  &lt;Style TargetType="{x:Type TreeViewItem}"&gt;
                      &lt;Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /&gt;
                      &lt;Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /&gt;
                      &lt;Setter Property="FontWeight" Value="Normal" /&gt;
                      &lt;Style.Triggers&gt;
                          &lt;Trigger Property="IsSelected" Value="True"&gt;
                              &lt;Setter Property="FontWeight" Value="Bold" /&gt;
                          &lt;/Trigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/TreeView.ItemContainerStyle&gt;
          &lt;/TreeView&gt;
      &lt;/Grid&gt;
  &lt;/ScrollViewer&gt;
  </code></pre>