title: Recursive TreeView does not retain structure when items added to underlying ObservableCollection
body: <p>Am building a recursive WPF TreeView out of this model:</p>
  
  <pre><code>public class Category
  {
      public virtual ICollection&lt;Category&gt; Category1 { get; set; }
      public virtual Category Category2 { get; set; }
  }
  </code></pre>
  
  <p>So (badly named) Category1 is a collection of child categories and Category2 is the parent Category. This latter can be null if it's at the top level of the tree.</p>
  
  <p>TreeView is being rendered like this:</p>
  
  <pre><code>&lt;TreeView ItemsSource="{Binding Categories}"&gt;
      &lt;TreeView.ItemTemplate&gt;
          &lt;HierarchicalDataTemplate ItemsSource="{Binding Category1}"&gt;
              &lt;Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ViewContentsCommand}" 
                  CommandParameter="{Binding}" Width="100" HorizontalAlignment="Stretch"&gt;
                  &lt;TextBlock FontWeight="Bold"  Text="{Binding Name}"&gt;&lt;/TextBlock&gt;
              &lt;/Button&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/TreeView.ItemTemplate&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>Categories is an ObservableCollection so that it should update when users add or remove items from the collection via the UI. In terms of display, this all works as expected.</p>
  
  <p>What I can't figure out is what happens when a user adds an item to the collection. Here's the code:</p>
  
  <pre><code>public void AddCategory()
  {
      Category c = new Category { Description = "New Category",  Category2Id = SelectedCategory.CategoryId };
      Categories.Add(c);
      OnPropertyChanged("Categories"); //to refresh the UI
  }
  </code></pre>
  
  <p>If you stick a breakpoint here and examine the Categories collection, it's as expected - the new item has slotted into the tree where it should, underneath its assigned ParentId. At the top level (i.e. items with null for Category2Id) there are the same number of items as before. But in the UI, this new item gets rendered as though it's at the top level instead of the correct place in the tree.</p>
  
  <p>At first, I wondered if this was a peculiarity of working with the ObservableCollection directly, so I tried this:</p>
  
  <pre><code>public void AddCategory()
  {
      List&lt;Category&gt; cats = Categories.ToList();
      Category c = new Category { Description = "New Category",  Category2Id = SelectedCategory.CategoryId };
      cats.Add(c);
      Categories = cats.ToObservableCollection();
  }
  </code></pre>
  
  <p>Which I expected to have no effect but which, to my surprise, resulted in nothing happening at all - i.e. the new category doesn't appear in the UI at all.</p>
  
  <p>What am I doing wrong?</p>