title: How to get the mouse position in a canvas when a context menu was clicked in WPF?
body: <p>I want to enable the user of my WPF application to dynamically add items to a canvas area. To do this I added a context menu with commmand binding as follows to the canvas:</p>
  
  <pre><code>&lt;Canvas Background="AliceBlue" Name="DensoWorkingArea"&gt;
      &lt;Canvas.ContextMenu&gt;
          &lt;ContextMenu&gt;
              &lt;MenuItem Header="Add New Platform" Command="{Binding AddPlatformCommand}" CommandParameter="{Binding ElementName=DensoWorkingArea}"&gt;
                  &lt;MenuItem.Icon&gt;
                      &lt;Image Source="\ExternalResources\Icons\Plus.ico" /&gt;
                  &lt;/MenuItem.Icon&gt;
              &lt;/MenuItem&gt;
          &lt;/ContextMenu&gt;
      &lt;/Canvas.ContextMenu&gt;
  &lt;/Canvas&gt;
  </code></pre>
  
  <p>In my <code>ViewModel</code> I have a <code>RelayCommand</code>:</p>
  
  <pre><code>public ICommand AddPlatformCommand
  {
      get
      {
          return addPlatformCommand ?? (addPlatformCommand = new RelayCommand(command =&gt; AddPlatformCommandClicked(command)));
      }
  }
  </code></pre>
  
  <p>And the called method looks as follows:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Method to add a new platform to the canvas
  /// &lt;/summary&gt;
  public void AddPlatformCommandClicked(object parameter)
  {
      Canvas canvas = parameter as Canvas;
      if (canvas == null) return;
      Point mousePos = Mouse.GetPosition(canvas);
      PlacementConfiguration.EquipmentPlacementList.Add(new EquipmentPlatformModel(new Point(0, 0)));
  }
  </code></pre>
  
  <p>My problem is, that the passed <code>parameter</code> argument is always <code>null</code>. 
  I have already tried to use a relative source as <code>CommandParameter</code> in the XAML which works as I get the context menu as parameter in the method. However I still need to know the mouse position relative to the canvas. </p>
  
  <p>I have also tried to go another route using windows blend however from the click event there, I also couldn't figure out how to get the mouse position within the canvas. </p>
  
  <p>The question is how to get the mouse position in my <code>AddPlatformCommandClicked()</code> method so I can then go on an place the item at the correct position. </p>