I am using commanding in my viewmodel to handle events. like for example I am handling a button click event like this:
XAML
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding mvvmButtonclick}" />
</i:EventTrigger>
</i:Interaction.Triggers>
Viewmodel Code
public ICommand mvvmButtonclick
{
get;
private set;
}
Viewmodel Constructor code to wireup the command
this.mvvmButtonclick = new ActionCommand(this.ButtonClickedEvent);
Actual method in the viewmodel that gets called on button click
private void ButtonClickedEvent()
{
MessageBox.Show("worked!!!");
}
This works. So my questions are:
- Is this the correct way?
- Is there a way I can propogate the (object sender, RoutedEventArgs e) parameters into my viewmodel and should I care if its not there?
- Suppose if this were a listbox selection changed event and not a button click. How do I get the value of the selected item without the object sender, SelectionChangedEventArgs e parameters?