title: WPF Treeview - How to automatically expand parents and select new node
body: <p>I have model objects set up like so:</p>
  
  <pre><code>public class Model
  {
      public ObservableCollection&lt;Model&gt; Children{get;set;}
      public string Name{get;set;}
  }
  </code></pre>
  
  <p>This gives me a tree of model objects of arbitrary size and depth. I display these in a WPF TreeView using a hierarchical datatemplate. Because of the ObservableCollection, I can add model objects anywhere in the model tree and the UI will update accordingly.</p>
  
  <p>The annoyance comes because even though a new model object might be added at the third level, for example, it might not be immediately visible.</p>
  
  <p>When a new model object is added anywhere in the tree, I would like the TreeView to automatically select the new node, and expand its parents to that it is immediately visible to the user. This doesn't seem to be immediately obvious.</p>
  
  <p>What I don't want to do is pollute the Model objects with properties which only make sense in a particular WPF control. Nor do I want to add a parent property to the Models.</p>
  
  <p>It seems that this must have been tackled before by someone. Does anyone have an idea on how to tackle this?</p>