We can use ICommand instead of Routed Event to implement MVVM, so we can write the logic in ViewModel.
Here is a example:
<Button Width="40" Command="{Binding CommandOne}">Click1
</Button>
But we need to Set CommandParameter all by ourself, and my problem is how to send the RoutedEventArgs as the CommandParameter.
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
How can I use the RoutedEventArgs as the CommandParameter in my ViewModel? Any ideas?
I don't think there is any straight forward way of doing this (nothing I know). But this can be achieved using interactivity EventTrigger
and defining your own TriggerAction
to capture the EventArgs
and send as CommandParameter
.
Here is one example of doing this. Here the example is of different event but can be applied to any.