title: Binding to ancestors from within a ResourceDictionary
body: <p>How can I bind to a <code>UserControl</code>'s property from within its <code>ResourceDictionary</code>? I want an object I declare in my resources to have the same <code>DataContext</code> as the <code>UserControl</code> it is contained in:</p>
  
  <pre><code>&lt;UserControl
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:Some.Namespace"
      DataContext="{Binding Path=ViewModel, RelativeSource={RelativeSource Self}}"&gt;
      &lt;UserControl.Resources&gt;
          &lt;local:SomeClass
              x:Key="SomeClass"
              DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" /&gt;
      &lt;/UserControl.Resources&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>At runtime I get the error:</p>
  
  <p><code>System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='UserControl', AncestorLevel='1''. BindingExpression:Path=DataContext; DataItem=null; target element is 'SomeClass' (Name=''); target property is 'DataContext' (type 'Object')</code></p>