title: WPF how to expose binding source as a resource
body: <p>I have a TabControl located in the ParentView. Inside that TabControl I have ChildView that contains a button with command bound to ParentViewModel's ICommand:</p>
  <pre><code>&lt;Button Command=&quot;{Binding DataContext.MyCommand, RelativeSource={RelativeSource AncestorType={x:Type local:ParentView}}}&quot;
          CommandParameter=&quot;{Binding}&quot;&gt;
  </code></pre>
  <p>Quite a few of these actually. Is there a way of creating UserControl resource from that RelativeSource and DataContext so I can declare my buttons more like that?:</p>
  <pre><code>&lt;Button Command=&quot;{Binding MyCommand, Source={StaticResource MyParentsDataContext}}&quot;
          CommandParameter=&quot;{Binding}&quot;&gt;
  </code></pre>
  <p><strong>Edit</strong></p>
  <p>What I came up so far is this:</p>
  <pre><code>&lt;UserControl.Resources&gt;
    &lt;RelativeSource x:Key=&quot;Parent&quot; AncestorType=&quot;{x:Type local:ParentView}&quot; /&gt;
  &lt;/UserControl.Resources&gt;
  
  &lt;Button Command=&quot;{Binding DataContext.MyCommand, RelativeSource={StaticResource Parent}}&quot;
          CommandParameter=&quot;{Binding}&quot;&gt;
  </code></pre>
  <p>Slightly dryer and more readable, but still not sure how to get rid of <code>DataContext</code> if possible at all.</p>