使用Microsoft.Xaml.Behaviors.Wpf可以使用MVVMLight的EventToCommand吗?

3
我使用了针对MVVM Light的System.Windows.Interactivity.WPF库。
由于System.Windows.Interactivity.WPF库发布日期较旧,所以我将其删除,并安装了Microsoft.Xaml.Behaviors.Wpf库并更新了相关内容。
工作进行得很顺利,只有一个问题。
问题是,如果我像下面这样使用Microsoft.Xaml.Behaviors.Wpf的交互和MVVMLight的EventToCommand,编译器会显示错误。
 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>

错误信息为“error MC3074: XML命名空间 'http://www.galasoft.ch/mvvmlight' 中不存在 EventToCommand 标记。”
如果我使用 CallMethodAction 或 InvokeCommand Microsoft.Xaml.Behaviors.Wpf,那么可以正常工作,但我必须使用 EventToCommand 来将参数传递到 Command。
我该怎么做来解决这个问题?有人能告诉我解决方案吗?
感谢阅读。
1个回答

4

简短回答:不行。

MvvmLight中的EventToCommand类继承自System.Windows.Interactivity.TriggerAction<T>,无法添加到Microsoft.Xaml.Behaviors.EventTriggerActions属性中。

因此,您有以下几个选择:

  1. 恢复使用System.Windows.Interactivity.dll
  2. 创建自己的EventToCommand类型,它继承自Microsoft.Xaml.Behaviors.TriggerAction<T>。您可以从GitHub上现有的实现开始。

感谢您的回答。 - jjw
请参见:https://github.com/lbugnion/mvvmlight/issues/96 - gigabot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接