title: How to bind from DataTemplate to Page's DataContext?
body: <p>I've got a page where a DataTemplate is being used to bind to the model for that content, e.g.:</p>
  
  <pre><code>&lt;DataTemplate x:DataType="models:MyDataType"&gt;
      ... content ...
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>In that content, I need to be able to bind a Click event. I need that click event to exist in the view model that is set as the page's DataContext:</p>
  
  <pre><code>&lt;Page.DataContext&gt;
      &lt;vm:MyViewModel x:Name="ViewModel"&gt;
  &lt;/Page.DataContext&gt;
  </code></pre>
  
  <p>but I'm really struggling with getting it to compile. Every approach I try results in the compilation error "Object reference not set to an instance of an object".</p>
  
  <p>I know I can't use x:Bind because that will bind to the DataTemplate's DataContext, so I've been trying to use Binding and, based on other SO answers I've read, it <em>seems</em> like the answer should be:</p>
  
  <pre><code>Click="{Binding DataContext.Button_Click, ElementName=Page}"
  </code></pre>
  
  <p>where Page is defined as the x:Name for the Page. I've tried removing DataContext. I've tried adding ViewModel.</p>
  
  <p>What am I misunderstanding? Is it not possible to do what I want to do? I've tried using code-behind instead but I'm using Template 10 and that pushes almost everything onto the view model, which makes it harder for me to access things like the navigation service from code-behind.</p>