Using MVVM, how to pass SelectedItems of a XamDataGrid as parameter to the Command raised by the Co
- by saddaypally
Hi, 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.
This is the snipped from the view
<ig:XamDataGrid DataSource="{Binding DrdResults}" Height="700" Width="600">
<ig:XamDataGrid.ContextMenu>
<ContextMenu DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.DataContext}" AllowDrop="True" Name="cmAudit">
<MenuItem Header="View History" Command="{Binding ViewTradeHistory}"
CommandParameter="{Binding Path=SelectedItems}">
</MenuItem>
</ContextMenu>
</ig:XamDataGrid.ContextMenu>
<ig:XamDataGrid.FieldSettings>
<ig:FieldSettings AllowFixing="NearOrFar" AllowEdit="False" Width="auto" Height="auto" />
</ig:XamDataGrid.FieldSettings>
</ig:XamDataGrid>
My code in the corresponding ViewModel for this View is as follows
public WPF.ICommand ViewTradeHistory
{
get
{
if (_viewTradeHistory == null)
{
_viewTradeHistory = new DelegateCommand(
(object SelectedItems) =
{
this.OpenTradeHistory(SelectedItems);
});
}
return _viewTradeHistory;
}
}
And lastly the actual method that gets called by the Command is as below
private void OpenTradeHistory(object records)
{
DataPresenterBase.SelectedItemHolder auditRecords = (DataPresenterBase.SelectedItemHolder)records;
// Do something with the auditRecords now.
}
I'm not sure what am I doing incorrectly here. Any help will be very much appreciated.
Thanks,
Shravan