title: WPF DataTemplate using same DataContext like parent control
body: <p>I am getting crazy about a DataContext problem in WPF. I read the comments here in StackOverflow, but I can't fixed it. </p>
  
  <p>I have the following data template :</p>
  
  <pre><code>&lt;DataTemplate  x:Key="TodoTemplate"  &gt;
      &lt;Grid Margin="5 10 10 5" &gt;
  
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="30" MaxWidth="30"/&gt;
              &lt;ColumnDefinition Width="30" MaxWidth="30"/&gt;
              &lt;ColumnDefinition Width="30" MaxWidth="30"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;Grid.ContextMenu&gt;
              &lt;ContextMenu&gt;
                  &lt;MenuItem Command="{Binding Path=View}"&gt;
                      &lt;MenuItem.Header&gt;
                          &lt;WrapPanel&gt;
                              &lt;Label Margin="30 0 0 0" Background="LightBlue"&gt;View Item&lt;/Label&gt;
                          &lt;/WrapPanel&gt;
                      &lt;/MenuItem.Header&gt;
                  &lt;/MenuItem&gt;
  </code></pre>
  
  <p>and a Listbox where I want to reuse my template :</p>
  
  <pre><code>    &lt;ListBox Grid.Row="4" ItemsSource="{Binding Path=Items}" Margin="10" ItemTemplateSelector="{StaticResource categoryItemSelector}" SelectedItem="{Binding Path=CurrentItem,Mode=TwoWay}" MouseDoubleClick="ListBox_MouseDoubleClick"  &gt;
  
      &lt;/ListBox&gt;
  </code></pre>
  
  <p>The Listbox code is embedded in a page and this page sets an DataContext for a view model instance.</p>
  
  <pre><code>  DataContext="{Binding Source={StaticResource Locator},Path=CategoryDetails}"&gt;
  </code></pre>
  
  <p>I've learned that the context menu is not part of the visual tree and the data context cannot be reused directly. The problem is, that I also have a MemoTemplate with the same context menu and I want to reuse my view model here. Can anyone givie me a hint to solve it?</p>
  
  <p>I tried to use the ContextService parameter and also to set a proxy. But my View command is not called via the context menu.</p>
  
  <p>How cam I reuse my view model instance from my page ( via the listbox ) here ?</p>
  
  <p>Thanks in advance
  Björn</p>