title: How to refresh treeview when ItemsSource changes?
body: <p>My TreeView is bound to an ObservableCollection and uses HierarchicalDataTemplates.</p>
  
  <p>I get the models from a web service. </p>
  
  <p>Only when users click a node in tree, a web service call will be sent to get its child items. </p>
  
  <p>My App has a TabControl, TreeView is on one tabpage, the other tabpage has a datagrid - it has some data selected from treeview. When an item in datagrid is right clicked, I want to locate the item on treeview.  But now the issue is when I iterate the treeview, 
  say, I have an item called </p>
  
  <blockquote>
    <p>A.A1.A11</p>
  </blockquote>
  
  <p>and my TreeView has 3 items in the first level: </p>
  
  <p>A<br>
  B<br>
  C  </p>
  
  <p>when I locate <strong>A.A1.A11</strong>, I want to <em>expand</em> A, A1, and <em>highlight</em> A11. </p>
  
  <p>When I iterate the treeview, first I find A, it matches first path of A.A1.A11, 
  so I send a web service request to get A's children.</p>
  
  <p>Once I get that, DataContext of the TreeViewItem of A is updated, but the TreeViewItem itself is not. </p>
  
  <p>So when I check A.Items, it is empty and iteratation is unable to continue.  </p>
  
  <p><strong>How can I refresh the TreeView &amp; TreeViewItem when its ItemsSource changes?</strong></p>
  
  <p>Here is the xaml for treeview definition</p>
  
  <pre><code>&lt;TreeView x:Name="TreeRoot" 
            ItemsSource="{Binding RootItems}" 
            TreeViewItem.Expanded="TreeViewExpanded"
            TreeView.SelectedItemChanged="TreeRootSelectedItemChanged"
            ContextMenu="{StaticResource DataGridContextMenu}"
            PreviewKeyDown="TreeViewKeyDown"
            PreviewMouseLeftButtonDown="TreeViewPreviewLeftMouseButtonDown"
            PreviewMouseMove="TreeViewPreviewMouseMove" &gt;
      &lt;TreeView.Resources&gt;
          &lt;HierarchicalDataTemplate 
              DataType="{x:Type m:TreeModelBase}" 
              ItemsSource="{Binding Children}"&gt;    
              &lt;StackPanel&gt;
                  &lt;Image Source="{Binding ImageFilePath}" /&gt;
                  &lt;TextBlock Text="{Binding Name}" /&gt;
                  &lt;!-- other items removed for brevity --&gt;
                  &lt;StackPanel.Style&gt;
                  &lt;Style TargetType="{x:Type StackPanel}"&gt;
                      &lt;Style.Triggers&gt;
                          &lt;DataTrigger Binding="{Binding IsSelected}"
                                       Value="True"&gt;  
                          &lt;Setter Property="Background" Value="DodgerBlue"/&gt;
                          &lt;Setter Property="TextBlock.Foreground" 
                                  Value="White"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding IsSelected}"
                                       Value="False"&gt;  
                          &lt;Setter Property="Background" Value="White"/&gt;
                          &lt;Setter Property="TextBlock.Foreground" 
                                  Value="Black"/&gt;
                          &lt;/DataTrigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/StackPanel.Style&gt;
              &lt;/StackPanel&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/TreeView.Resources&gt;
  &lt;/TreeView&gt;
  </code></pre>