I’m little confused about RelayCommand and EventToCommand in Mvvmlight.
It seems that EventToCommand handle the EventTrigger and call a RelayCommand to do job.
Such as:
<i:Interaction.Triggers>
<i:EventTrigger x:Uid="i:EventTrigger_1" EventName="MouseLeftButtonUp">
<cmd:EventToCommand x:Uid="cmd:EventToCommand_1" Command="{Binding Form_MouseLeftButtonUpCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
Is my understanding correct?
So, can we use RelayCommand directly with EventTrigger, no need to use EventToCommand?
Thanks for your help!
EventToCommandis a custom behavior. It is first provided by Expression blend team and now Part of WPF 4. If you’re not using WPF4. you require Blend SDK from here.Behaviors encapsulates functionality as reusable components. These are to be used when feature is not present by default. For example Adding Command support to Label, Combobox etc.
No.
RelayCommandis a shortcut to avoid code redudnency to define custom commands.It extendsICommandwhose delegates can be attached forExecute(T)andCanExecute(T). It is similar toDelegateCommandof Prism library.In above line
cmd:EventToCommandis additional feature to the underlying control.Form_MouseLeftButtonUpCommandis theCommandit executes. This command can be encapsulated asRelayCommand.