title: WPF ContextMenu woes: How do I set the DataContext of the ContextMenu?
body: <p>I am having some trouble figuring out how to set the correct <code>DataContext</code> on a <code>ContextMenu</code>. </p>
  
  <p>I have a collection of view models who are the source of an <code>ItemsControl</code>.  Each view model has a collection of items which are also the source of another <code>ItemsControl</code>.  Each item is used to draw image which has a <code>ContextMenu</code>.  The <code>MenuItems</code> in that <code>ContextMenu</code> need to bind to a command on the view model, but the <code>PlacementTarget</code> of the <code>ContextMenu</code> is pointing to the individual item.</p>
  
  <p>My Xaml looks something like this:</p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding Markers"}&gt;
      &lt;ItemsControl.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;ItemsControl ItemsSource="{Binding Items}"&gt;
                  &lt;ItemsControl.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Image&gt;
                              &lt;Image.ContextMenu&gt;
                                  &lt;ContextMenu&gt;
                                       &lt;MenuItem Header="Edit" Command="{Binding EditCommand}" /&gt;
                                  &lt;/ContextMenu&gt;
                              &lt;/Image.ContextMenu&gt;
                          &lt;/Image&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ItemsControl.ItemTemplate&gt;
              &lt;/ItemsControl&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>How can I set the <code>DataContext</code> of the <code>ContextMenu</code> to the item's corresponding parent view model?</p>