title: WPF: Make a UserControl with a Treeview behave like a vanilla Treeview
body: <p>I'm learning WPF, and I think I'm missing something with user controls. I'll try and demonstrate by example. Basically, suppose I have a treeview, and I want to bind a labels text to the treeviews selectedItem. This seems simple : </p>
  
  <pre><code>&lt;!-- Window.xaml --&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition /&gt;
          &lt;RowDefinition Height="100" /&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;TreeView Name="MyTreeView"&gt;
          &lt;TreeViewItem Header="Root"&gt;
              &lt;TreeViewItem Header="Item1"&gt;&lt;/TreeViewItem&gt;
              &lt;TreeViewItem Header="Item2"&gt;&lt;/TreeViewItem&gt;
          &lt;/TreeViewItem&gt;
      &lt;/TreeView&gt;
  
      &lt;Label Content="{Binding ElementName=MyTreeView, Path=SelectedItem.Header}" Grid.Row="1"&gt;&lt;/Label&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Now, to complicate things I'll add a user control into the mix. The user control is basically a TreeView in a grid : </p>
  
  <pre><code>&lt;!-- ExampleUserControl.xaml --&gt;
  &lt;UserControl&gt;
      &lt;Grid&gt;
          &lt;TreeView Name="UserControlTreeView"&gt;
              &lt;TreeViewItem Header="Root"&gt;
                  &lt;TreeViewItem Header="Item1"&gt;&lt;/TreeViewItem&gt;
                  &lt;TreeViewItem Header="Item2"&gt;&lt;/TreeViewItem&gt;
              &lt;/TreeViewItem&gt;
          &lt;/TreeView&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>The intent is to replace the vanilla treeview used above with the usercontrol, and have the labels content changed based on what is selected. So, I try something like this : </p>
  
  <pre><code>&lt;Window&gt;    
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition /&gt;
              &lt;RowDefinition Height="100" /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;local:ExampleUserControl1 x:Name="MyUserControl"&gt;            
          &lt;/local:ExampleUserControl1&gt;
  
          &lt;Label Content="{Binding ElementName=MyUserControl, Path=SelectedItem.Header}" Grid.Row="1"&gt;&lt;/Label&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>This compiles and runs, but when I select items in the treeview, the label doesn't change. I think I understand why : the user control contains a treeview, but is clearly not a treeview. I'm not sure on the best way to fix this. I can think of one way that seems problematic : </p>
  
  <ul>
  <li>Add a property 'SelectedItem' to the user control in code, that returns the treeviews selected item. </li>
  </ul>
  
  <p>This would work for one property, or a few, but the thought of doing this for each property in treeview seems like a serious waste of code + time. Is there some way to still use the user control, but make it behave like a normal TreeView?</p>