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?
A parameter can be passed through the "CommandParameter" property. Once the button is clicked the selected address value is passed to the ICommand. Execute method. The CommandParameter is sent to both CanExecute and Execute events.
Commands are an implementation of the ICommand interface that is part of the . NET Framework. This interface is used a lot in MVVM applications, but it is useful not only in XAML-based apps.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With