title: TabItem binding content dynamically
body: <p>Trying to build a TabControl dynamically, but it won't bind the UserControl I've created.  I've extended TabItem to add some close functionality to the header.</p>
  
  <p>The error it gives is:</p>
  
  <pre><code>System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type; Type='ClosableTab'
  </code></pre>
  
  <p>I end up with System.Windows.Controls.Grid in plain text rather than a control.  The UserControl is just containing a TextBlock in an empty grid for testing purposes.</p>
  
  <p>The error is remarkably similar to this question: <a href="https://stackoverflow.com/questions/44457888/data-error-26-with-datatemplate-and-itemtemplate#">Data Error 26 with DataTemplate and ItemTemplate</a> but my code is different and I can't figure out if it's the same, but I have tried to search.</p>
  
  <p>And this code contains is sourced from multiple tutorials, I'm still only a month in so sorry if I've missed something obvious.</p>
  
  <pre><code>&lt;TabControl TabStripPlacement="Top"
              ItemsSource="{Binding Titles, Mode=TwoWay}"
              Grid.Column="3" Grid.Row="1"&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;TextBlock Text="{Binding Content}" /&gt;
          &lt;/DataTemplate&gt;
      &lt;/TabControl.ContentTemplate&gt;
  &lt;/TabControl&gt;
  </code></pre>
  
  <p>The extended TabItem class.  TabHeader is just Xaml to add a close button to the header, works fine.
  {Binding Content} does show a warning, </p>
  
  <pre><code>Cannot resolve property 'Content' in data context of type MyApp.ViewModel.MainWindowViewModel
  </code></pre>
  
  <p>Perhaps this is key?</p>
  
  <pre><code>public class ClosableTab : TabItem
  {
      public ClosableTab(string headerText, UserControl content)
      {
          TabHeader header = new TabHeader();
          Header = header;
          Title = headerText;
          Content = content;
      }
  
      public string Title
      {
          get { return Title.ToString(); }
          set
          {
              ((TabHeader)this.Header).label_TabTitle.Content = value;
          }
      }
  }
  </code></pre>
  
  <p>The ICommand event handler</p>
  
  <pre><code>private ObservableCollection&lt;ClosableTab&gt; _titles; 
  
  public ObservableCollection&lt;ClosableTab&gt; Titles
  {
      get { return _titles; }
      set
      {
          _titles = value;
          OnPropertyChanged("Titles");
      }
  }
  
  private void AddTabItem(string title)
  {
      ClosableTab Item;
      Item = new ClosableTab("Setup", new Setup());
      Titles.Add(Item);
      Item.Focus();
      OnPropertyChanged("Titles");
  }
  </code></pre>
  
  <p>New Setup() is a user control containing just a Grid and a TextBlock.</p>
  
  <p>Everything works perfectly, the header is built with the title and close button, but the content just returns text, System.Windows.Controls.Grid?</p>