title: Bind CommandParameter from MenuItem to Parent DataGrid
body: <p>How can I bind a command parameter from MenuItem to parent Grid DataContext?</p>
  
  <p>I have a DataGrid with ContextMenu, binding the menu items to ViewModel commands, but the command parameter is always null.</p>
  
  <p>I use Tag parameter into DataGrid to get access into DataContext and use the desired command but could figure it out to get the binding data from every row to use as a command parameter.</p>
  
  <p>I had already looked into many answers here, but couldn't find anyone that works, the command parameter inside the ViewModel is called and command parameter is always null.</p>
  
  <p><strong>C#</strong></p>
  
  <pre><code>public class People
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  
  public class PeopleWindowViewModel
  {
      public List&lt;People&gt; Peoples { get; set; }
  
      public PeopleWindowViewModel()
      {
          // populate Peoples list...
      }
  
      public ICommand RemoveCommand
      {
          get
          {
              return RelayCommand.Create((m) =&gt;
              {
                  // m always null
              });
          }
      }
  }
  
  public class PeoplePage : Page
  {
      public PeoplePage()
      {
          InitializeComponent();
  
          DataContext = new PeopleWindowViewModel();
      }
  }
  </code></pre>
  
  <p><strong>XAML:</strong>
      
        
          
        </p>
  
  <pre><code>  &lt;DataGrid
        Margin="0 8 0 8"
        d:DataContext="{d:DesignInstance local:People}"
        IsReadOnly="True"
        ItemsSource="{Binding Peoples}"
        Tag="{Binding DataContext,
                        RelativeSource={RelativeSource AncestorType={x:Type Page}}}"&gt;
      &lt;DataGrid.Columns&gt;
        &lt;DataGridTextColumn
            Binding="{Binding Id}"
            Header="Id" /&gt;
        &lt;DataGridTextColumn
            Binding="{Binding Name}"
            Header="Name" /&gt;
      &lt;/DataGrid.Columns&gt;
  
      &lt;DataGrid.ContextMenu&gt;
        &lt;ContextMenu
            Tag="{Binding Path=PlacementTarget.Tag,
                                RelativeSource={RelativeSource Self}}"&gt;
          &lt;MenuItem
              Command="{Binding PlacementTarget.Tag.RemoveCommand,
                                        RelativeSource={RelativeSource Mode=FindAncestor,
                                                                       AncestorType=ContextMenu}}"
              CommandParameter="{Binding Path=Id,
                                                 RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                AncestorType=DataGrid}}"
              Header="Remover" /&gt;
        &lt;/ContextMenu&gt;
      &lt;/DataGrid.ContextMenu&gt;
    &lt;/DataGrid&gt;
  &lt;/Page&gt;
  </code></pre>