Using MVVM, how to pass SelectedItems of a XamDataGrid as parameter to the Command raised by the Co

Posted by saddaypally on Stack Overflow See other posts from Stack Overflow or by saddaypally
Published on 2010-06-09T06:41:53Z Indexed on 2010/06/09 8:32 UTC
Read the original article Hit count: 2067

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvvm