title: What's the DataContext of TabControl.ItemTemplate?
body: <p>Given the following XAML:</p>
  
  <pre><code>&lt;TabControl DataContext="{StaticResource mainVM}" ItemsSource="{Binding MovableVM.Docked, UpdateSourceTrigger=PropertyChanged}"&gt;
          &lt;TabControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;TextBlock&gt;
                      &lt;TextBlock Text="{Binding ContentTitle}"/&gt;
                  &lt;/TextBlock&gt;
              &lt;/DataTemplate&gt;
          &lt;/TabControl.ItemTemplate&gt;
          &lt;TabControl.ContentTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;ContentPresenter Content="{Binding}"/&gt;
              &lt;/DataTemplate&gt;
          &lt;/TabControl.ContentTemplate&gt;
  &lt;/TabControl&gt;
  </code></pre>
  
  <p>I expected both <code>DataTemplate</code>s to have the same <code>DataContext</code> with the expected result that the actual items from the ItemsSource (a <code>UserControl</code> implementing the interface IMovable, see below) being displayed within separate tabs and the header of each tab to display the contents of the property ContentTitle of the same item.</p>
  
  <p>The <code>IMovable</code> object <em>is</em> displayed as expected, but the binding to the ContentTitle is <em>not</em> working for the header. If I change the the binding in the <code>ContentTemplate</code>, like so...</p>
  
  <pre><code>&lt;TabControl.ContentTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;ContentPresenter Content="{Binding ContentTitle}"/&gt;
      &lt;/DataTemplate&gt;
  &lt;/TabControl.ContentTemplate&gt;
  </code></pre>
  
  <p>...I do get the contents of the ContentTitle property instead of the item, so the property itself is bindable. </p>
  
  <p>Here's the <code>IMovable</code> interface:</p>
  
  <pre><code>public interface IMovable : INotifyPropertyChanged
  {
      string ContentTitle { get; }
  }
  </code></pre>
  
  <p>So my question is: Is there a different DataContext in the ItemTemplate (if so, what is it?) or is there another reason the binding in the ItemTemplate isn't working as I expect?</p>
  
  <p><strike><strong>Update:</strong>
  I've created a small example application that shows the problem clearly. If things had worked as expected, there would be a text below each Ellipse in each tab, and the DataContext of the Ellipse would not be null. It can be downloaded here: <a href="http://www.codezeal.com/stackoverflow/WpfApplication2.zip" rel="nofollow">Example App</a></strike></p>
  
  <p><strong>Update</strong>
  It works if using a custom class <code>Foo::DependencyObject</code> and making the ContentTitle property into a DependencyProperty. Though changing the property in the original class does not work. I need to sleep on this....</p>
  
  <p><strong>Update</strong>
  I've narrowed down the problem, but the findings are not at all what I expected. <a href="http://www.codezeal.com/stackoverflow/WpfApplication2.zip" rel="nofollow">WpfApplication2</a> shows that adding items to the ItemsSource that are either POCO or derived from DependedcyObject works as expected. However, items derived from UserControl do not give the expected result. I would appreciate if someone you have a look at it. Simply run the application and you'll see that one Tab header is missing the text.</p>