title: Using MVVM, how to pass SelectedItems of a XamDataGrid as parameter to the Command raised by the ContextMenu?
body: <p>I'm trying to pass the item on XamDataGrid on which I do a mouse right click to open a ContextMenu, which raises a Command in my ViewModel. Somehow the method that the Command calls is not reachable in debug mode.</p>
  
  <p>This is the snipped from the view</p>
  
  <pre><code>&lt;ig:XamDataGrid DataSource="{Binding DrdResults}" Height="700" Width="600"&gt;
    &lt;ig:XamDataGrid.ContextMenu&gt;
      &lt;ContextMenu DataContext="{Binding RelativeSource={RelativeSource Mode=Self},
                                 Path=PlacementTarget.DataContext}"
                   AllowDrop="True" Name="cmAudit"&gt;
        &lt;MenuItem Header="View History" 
                  Command="{Binding ViewTradeHistory}"
                  CommandParameter="{Binding Path=SelectedItems}"&gt;
        &lt;/MenuItem&gt;
      &lt;/ContextMenu&gt;
    &lt;/ig:XamDataGrid.ContextMenu&gt;
    &lt;ig:XamDataGrid.FieldSettings&gt;
      &lt;ig:FieldSettings AllowFixing="NearOrFar"
                        AllowEdit="False" 
                        Width="auto" Height="auto"  /&gt;
    &lt;/ig:XamDataGrid.FieldSettings&gt;
  &lt;/ig:XamDataGrid&gt;
  </code></pre>
  
  <p>My code in the corresponding ViewModel for this View is as follows.</p>
  
  <pre><code>public WPF.ICommand ViewTradeHistory
  {
    get
    {
      if (_viewTradeHistory == null)
      {
        _viewTradeHistory = new DelegateCommand(
        (object SelectedItems) =&gt;
        {
          this.OpenTradeHistory(SelectedItems); 
        });
      }
      return _viewTradeHistory;
    }
  }
  </code></pre>
  
  <p>And lastly the actual method that gets called by the Command is as below</p>
  
  <pre><code>private void OpenTradeHistory(object records)
  {
    DataPresenterBase.SelectedItemHolder auditRecords
      = (DataPresenterBase.SelectedItemHolder)records;
    // Do something with the auditRecords now.
  }
  </code></pre>
  
  <p></p>
  
  <p>I'm not sure what am I doing incorrectly here. Any help will be very much appreciated.</p>
  
  <p>Thanks,
  Shravan</p>