title: ItemsControl ItemTemplate Binding
body: <p>In WPF4.0, I have a class that contains other class types as properties (combining multiple data types for display).  Something like:</p>
  <pre><code>public partial class Owner
  {
       public string OwnerName { get; set; }
       public int    OwnerId   { get; set; }
  }
  
  partial class ForDisplay
  {
      public Owner OwnerData { get; set; }
      public int Credit { get; set; }
  }
  </code></pre>
  <p>In my window, I have an ItemsControl with the following (clipped for clarity):</p>
  <pre><code>&lt;ItemsControl ItemsSource={Binding}&gt;
      &lt;ItemsControl.ItemTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;local:MyDisplayControl 
                  OwnerName={Binding OwnerData.OwnerName}
                  Credit={Binding Credit} /&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  <p>I then get a collection of display information from the data layer, and set the <code>DataContext</code> of the <code>ItemsControl</code> to this collection.  The &quot;Credit&quot; property gets displayed correctly, but the OwnerName property does not.  Instead, I get a binding error:</p>
  <blockquote>
  <p>Error 40: BindingExpression path
  error: 'OwnerName' property not found
  on 'object' ''ForDisplay'
  (HashCode=449124874)'.
  BindingExpression:Path=OwnerName;
  DataItem='ForDisplay'
  (HashCode=449124874); target element
  is 'TextBlock' (Name=txtOwnerName');
  target property is 'Text' (type
  'String')</p>
  </blockquote>
  <p>I don't understand why this is attempting to look for the OwnerName property in the ForDisplay class, rather than in the Owner class from the ForDisplay OwnerData property.</p>
  <p><strong>Edit</strong>
  It appears that it has something to do with using the custom control.  If I bind the same properties to a <code>TextBlock</code>, they work correctly.</p>
  <pre><code>&lt;ItemsControl ItemsSource={Binding}&gt;
      &lt;ItemsControl.ItemTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;StackPanel&gt;
                &lt;local:MyDisplayControl 
                          OwnerName={Binding OwnerData.OwnerName}
                          Credit={Binding Credit} /&gt;
                &lt;TextBlock Text=&quot;{Binding OwnerData.OwnerName}&quot; /&gt;
                &lt;TextBlock Text=&quot;{Binding Credit}&quot; /&gt;
            &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  </code></pre>