9

Using MVVM-Light Toolkit in Silverlight 5, i am trying to find a way to pass Command Parameters AND EventArgs both to ViewModel in an Event-To-Command behavior.

I did find a post suggesting Passing EventArgs as Command Parameters but in my case i want to use EventArgs and Command Parameter both in ViewModel.

Anyone can help?

Thr3e
  • 358
  • 1
  • 6
  • 22
  • is this even possible using MVVM-Light toolkit? – Thr3e Jul 10 '12 at 01:25
  • I would create a lightweight object that contains the information I need from the event args and the object I was normally going to send as the command parameter and just use that new lightweight object as my command parameter. – Stewart Sweet Jul 11 '12 at 00:02
  • @StewartSweet Sorry but how can you create such an object in view? can you kindly show an example? – Thr3e Jul 12 '12 at 00:58

1 Answers1

11

Solved the Issue .... in case if anyone else is wondering ...

Concept : We only need to pass the EventArgs via MVVM-Light Event to Command. In event to Command, there is a property Source. we can cast this 'Source' Property to the object that generated this command.

Example :

we declare command with eventargs in ViewModel Constructor

FilterQuotationsCommand = new RelayCommand<GridViewFilteredEventArgs>(FilterQuotationsCommandExecute);

And we Access the Sender via the "Source" after casting it to the sending control.

private void FilterQuotationsCommandExecute(GridViewFilteredEventArgs e)
    {
        var grid = (RadGridView) e.Source; // we casted the Source to Grid
        var item = grid.SelectedItem;      // we can access grid's selected items
    }
Thr3e
  • 358
  • 1
  • 6
  • 22