title: WPF TemplateBinding to DataContext of templated parent
body: <p>We have four identical popups with grids in four XAML views. I'd like to move that XAML to a template and apply via a Style to to ContentControls in all four of them. The trouble is passing in the source of the items in the grids. We get that from each of four different view models. It's different in each case, the only thing that differs among the four cases. I'll probably end up renaming them consistently, but I'd like to think that's a separate issue. </p>
  
  <p>Obviously I don't understand TemplateBinding at all. How do I bind a property of a child of the template to a property of the ContentControl that I'm applying the template to? </p>
  
  <p>Except for the value of the DataSource attribute changing, the XAML for the grid is identical to what works perfectly well when we use it directly. </p>
  
  <p>I added the TextBlock just to see if I could bind anything at all. I do get <code>NaN</code> there. </p>
  
  <pre><code>&lt;Style x:Key="HistoryPopupContentStyle" TargetType="ContentControl"&gt;
      &lt;Setter Property="ContentTemplate"&gt;
          &lt;Setter.Value&gt;
              &lt;DataTemplate&gt;
                  &lt;StackPanel Orientation="Vertical"&gt;
                      &lt;TextBlock Text="{TemplateBinding Width, 
                       diag:PresentationTraceSources.TraceLevel=High}"
                                 Background="White"
                                 Foreground="Black"/&gt;
                  &lt;dxg:GridControl
                      DataSource="{Binding RelativeSource={RelativeSource 
                       Path=DataContext, 
                       TraceLevel=High}"
                      VerticalAlignment="Stretch" 
                      HorizontalAlignment="Stretch" 
                      &gt;
                          &lt;!-- Columns. The grid displays column headers 
                                   as desired but with no rows --&gt;
                      &lt;/dxg:GridControl.Columns&gt;
                  &lt;/dxg:GridControl&gt;
                  &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  
  &lt;Popup 
      Name="PopHistory" 
      DataContext="{Binding Path=HistoryList}"
      &gt;
      &lt;ContentControl DataContext="{Binding Path=HistoryList}"
                      Style="{StaticResource HistoryPopupContentStyle}"
                      Name="Testing"
                      /&gt;
  &lt;/Popup&gt;
  </code></pre>