wpfeventtocommand

Is there a way to use the EventToCommand of the MVVMLight in the Microsoft.Xaml.Behaviors.Wpf?


I have used System.Windows.Interactivity.WPF library with MVVM Light.

I deleted System.Windows.Interactivity.WPF library because it's publishing date is old. And I installed Microsoft.Xaml.Behaviors.Wpf library and updated related to content.

The work went smoothly except for one. The problem is if I use the interaction of Microsoft.Xaml.Behaviors.Wpf with EventToCommand of the MVVMLight as below, compiler shows error.

 xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
 xmlns:mvvm="http://www.galasoft.ch/mvvmlight"

<i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectedItemChanged">
        <mvvm:EventToCommand Command="{Binding CPUSelectedCommand}"
                         PassEventArgsToCommand="True"
                         EventArgsConverter="{localConverters:SelectedItemConverter}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

The error message is "error MC3074: There is not EventToCommand tag in the XML namespace 'http://www.galasoft.ch/mvvmlight'."

If I use CallMethodAction or InvokeCommand Microsoft.Xaml.Behaviors.Wpf then works well but I have to use EventToCommand because of to pass the parameter to the Command.

What I should do to solve this problem? Could someone tell me the solution?

Thanks for reading.


Solution

  • Short answer: No.

    The EventToCommand class in MvvmLight inherits from System.Windows.Interactivity.TriggerAction<T> and cannot be added to the Actions property of a Microsoft.Xaml.Behaviors.EventTrigger.

    So your options are:

    1. Revert back to using System.Windows.Interactivity.dll.
    2. Create your own EventToCommand type that inherits from Microsoft.Xaml.Behaviors.TriggerAction<T>. You may start from the existing implementation on GitHub.