title: WPF Getting mouse coordinates within viewmodel
body: <p>I have a WPF project (C#, MVVM Light, Visual Studio 2010).</p>
  
  <p>I have a bit of a problem regarding separation of concerns (MVVM) which basically is this: I have a command in a view model. I have a context menu that I want to call that command. So far so good. The problem is that the command needs to coordinates that the mouse was clicked. </p>
  
  <p>To be a little more specific, the ContextMenu only appears if you click on a particular Canvas control, and it's the coordinates within said Canvas control that I want. </p>
  
  <p>The easy way to do this is to manage it all in the code behind of the XAML document (and I have been able to do it that way), but I'd rather have it within my ViewModel if I can do so. The reason is that there are calls to my data model within this command so we end up with a problem of separation.</p>
  
  <p>I am aware of PassEventArgsToCommand, and I'm aware that it's a bad practise, however in this case I'm not sure I can see a way around it. So for the moment I did try that, and it looks like this:</p>
  
  <pre><code>&lt;ContextMenu x:Key="BackgroundMenu"&gt;
              &lt;MenuItem Header="Add new node here"&gt;
                  &lt;i:Interaction.Triggers&gt;
                      &lt;i:EventTrigger EventName="Click"&gt;
                          &lt;cmd:EventToCommand Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.DataContext.AddNewNodeAtLocationCommand}" PassEventArgsToCommand="True"/&gt;
                      &lt;/i:EventTrigger&gt;
                  &lt;/i:Interaction.Triggers&gt;
              &lt;/MenuItem&gt; 
          &lt;/ContextMenu&gt;
  </code></pre>
  
  <p>So now my command, within the view model, looks like this:</p>
  
  <pre><code>void AddNewNodeAtLocationExecute(RoutedEventArgs e)
      {
  
          return;
      }
  </code></pre>
  
  <p>Within that method I'd like to get those mouse coordinates, but I don't know if it's possible. e.OriginalSource is 'MenuItem', which doesn't help much.</p>
  
  <p>So how can I do this? Can I do this? Or should I just have this one command handled by the code behind? Said code will involve a call to the database, which is why I'm being so particular about the separation.</p>
  
  <p>Thanks in advance.</p>