Question

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?

Was it helpful?

Solution

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
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top