Question

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?

Was it helpful?

Solution

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.

http://social.msdn.microsoft.com/Forums/silverlight/en-US/5cd586e7-640f-447b-9040-e9270173abf7/passing-drop-event-data-in-a-command-parameter-using-mvvm-and-the-interactivity-framework

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top