title: Put Treeviews in TabControl content pages
body: <p>I'm currently building a XML editor and now I want to implement the ability to open and edit multiple XML files concurrently. Every file should be represented by a tab in a TabControl while the content of the tab shows a hierarchical TreeView of the XML structure.</p>
  
  <p>Since I'm in no way an expert on XAML data binding I'm having trouble to populate the treeview from the view model object I already implemented.</p>
  
  <p><strong>My window:</strong></p>
  
  <pre><code>public partial class EditorWindow : Window
  {
      private ObservableCollection&lt;FileTab&gt; tabList;
  
      public EditorWindow()
      {
          InitializeComponent();
  
          xsdManager = null;
          tabList = new ObservableCollection&lt;FileTab&gt;();
  
          editorWindow.DataContext = tabList;
          tabControl.ItemsSource = tabList;
  
          FileTab pt = new FileTab(@"C:\Users\User\Documents\Test.xml");
          tabList.Add(pt);
          refreshTabControl();
  
      }
  
      private void OpenButtonClick(object sender, RoutedEventArgs e)
      {
          OpenFileDialog fileDialog = new OpenFileDialog();
          fileDialog.DefaultExt = ".xml";
          fileDialog.Filter = "XML files (.xml)|*.xml";
          Nullable&lt;bool&gt; result = fileDialog.ShowDialog();
  
          if (result == true)
          {
              string filename = fileDialog.FileName;
              Console.WriteLine("MainWindow.SchemaButtonClick:: " + filename);
  
              tabList.Add(new FileTab(filename));
              Console.WriteLine("New Tab: " + Path.GetFileName(filename));
  
              refreshTabControl();
          }
      }
  
      private void refreshTabControl()
      {
          tabControl.Items.Refresh();
      }
  }
  </code></pre>
  
  <p><strong>My Window XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="XmlTool.EditorWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:XmlTool"
          Title="EditorWindow" Height="300" Width="300" Name="editorWindow"&gt;
      &lt;StackPanel&gt;
          &lt;Button Click="OpenButtonClick"&gt;Open XML&lt;/Button&gt;
          &lt;TabControl Name="tabControl" ItemsSource="{Binding tabList}" Height="200"&gt;
              &lt;TabControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;TextBlock Text="{Binding header}" /&gt;
                  &lt;/DataTemplate&gt;
              &lt;/TabControl.ItemTemplate&gt;
              &lt;TabControl.ContentTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;TreeView Name="xmlTreeView"&gt;
                          &lt;TreeView.ItemTemplate&gt;
                              &lt;HierarchicalDataTemplate ItemsSource="{Binding treeRoot}" DataType="{x:Type local:XElementViewModel}"&gt;
                                  &lt;Label Name="elementNameLabel" Content="{Binding ElementName=treeRoot, Path=name}"/&gt;
                              &lt;/HierarchicalDataTemplate&gt;
                          &lt;/TreeView.ItemTemplate&gt;                        
                      &lt;/TreeView&gt;
                  &lt;/DataTemplate&gt;
              &lt;/TabControl.ContentTemplate&gt;
          &lt;/TabControl&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>The class XElementViewModel is the view model for an XElement and contains all child elements in a List of XElementViewmodel objects.</p>
  
  <p><strong>Class FileTab:</strong></p>
  
  <pre><code>class FileTab
      {
          public string header { get; set; }
          public XElementViewModel treeRoot { get; set; }
  
          public FileTab()
          {
              header = "Default tab";
              treeRoot = new XElementViewModel(@"C:\Users\User\Documents\ExampleXMLs\Test.xml");
          }
  
          public FileTab(string path) 
          {
              header = Path.GetFileName(path);
              Console.WriteLine("ProjectTab: header = " + header);
              treeRoot = new XElementViewModel(path);
              Console.WriteLine("ProjectTab: treeRoot.name = " + treeRoot.name);
          }
      }
  </code></pre>
  
  <p>The current code correctly adds new tabs named like the opened file, but it doesn't display the Treeview at all. As I said I'm not that good with data binding so any advice about that would help!</p>