title: How to set DataContext to self
body: <p>My UserControl requires binding to the ancestor (the ancestor being the MainWindow) and to itself (it's code behind).</p>
  
  <p>To bind to the ancestor, I'm using </p>
  
  <pre><code>DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1,AncestorType=Window}}"&gt; 
  </code></pre>
  
  <p>To bind a control to the code behind (and thus using the 'local' DataContext), I'm using </p>
  
  <pre><code>&lt;TextBlock Text ="{Binding MyUC3Property}" Name="MyName" /&gt;
  </code></pre>
  
  <p>and in the code behind, setting it like</p>
  
  <pre><code>this.MyName.DataContext = this;
  </code></pre>
  
  <p>The above works fine, where I can bind to the codebehind and to the ancestor. </p>
  
  <p>Now, I still want to bind to the code behind and the ancestor but set the DataContext in the XAML only (if possible).</p>
  
  <p>I've tried</p>
  
  <pre><code>&lt;TextBlock Text ="{Binding MyUC3Property}" DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}" /&gt; 
  </code></pre>
  
  <p>and ensured the constructor does not set the DataContext (since I want it all done in the XAML) - (although even if I do set <code>this.DataContext = this;</code> the error persists)</p>
  
  <p>and the output window tells me there is a binding error. </p>
  
  <blockquote>
    <p>System.Windows.Data Error: 40 : BindingExpression path error: 'MyUC3Property' property not found on 'object' ''TextBlock' (Name='')'. BindingExpression:Path=MyUC3Property; DataItem='TextBlock' (Name=''); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')</p>
  </blockquote>
  
  <p>I guess I'm missing something obvious, but I can't tell what.</p>