title: WPF: TreeView inside a ComboBox
body: <p>I'm trying to put a TreeView inside a ComboBox in WPF so that when the combo box is dropped, instead of a flat list the user gets a hierarchical list and whatever node they select becomes the selected value of the ComboBox.</p>
  
  <p>I've searched quite a bit for how to accomplish this but the best I could find was only peices of potential soltuions that, because I'm ridiculously new to WPF, I couldn't make work. </p>
  
  <p>I have enough knowledge of WPF and databinding that I can get my data into the treeview and I can even get the treeview inside of the combo box, however what I've been able to accomplish doesn't behave properly at all. I've attached a screenshot to show what I mean. In the screenshot the combo box is "open", so the treeview on the bottom is where I can select a node and the treeview "on top" is being drawn on top of the combobox where I want the text/value of the selected node in the tree to be displayed.</p>
  
  <p>Basically what I don't know how to do is how do I get the treeview's currrently selected node to return its value back up to the combobox which then uses it as its selected value?</p>
  
  <p>Here is the xaml code I'm currently using:</p>
  
  <pre><code>        &lt;ComboBox Grid.Row="0" Grid.Column="1"  VerticalAlignment="Top"&gt;
          &lt;ComboBoxItem&gt;
              &lt;TreeView ItemsSource="{Binding Children}" x:Name="TheTree"&gt;
                  &lt;TreeView.Resources&gt;
                      &lt;HierarchicalDataTemplate DataType="{x:Type Core:LookupGroupItem}" ItemsSource="{Binding Children}"&gt;
                          &lt;TextBlock Text="{Binding Path=Display}"/&gt;                            
                      &lt;/HierarchicalDataTemplate&gt;
                  &lt;/TreeView.Resources&gt;
              &lt;/TreeView&gt;
          &lt;/ComboBoxItem&gt;
      &lt;/ComboBox&gt;
  </code></pre>
  
  <p>Screenshot: <img src="https://i.stack.imgur.com/oi95R.jpg" alt="TreeView"> </p>