【问题标题】:Is there a way to use the EventToCommand of the MVVMLight in the Microsoft.Xaml.Behaviors.Wpf?有没有办法在 Microsoft.Xaml.Behaviors.Wpf 中使用 MVVMLight 的 EventToCommand?
【发布时间】:2020-04-30 22:09:22
【问题描述】:

我已将 System.Windows.Interactivity.WPF 库与 MVVM Light 一起使用。

我删除了 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>

错误消息是“错误MC3074:XML命名空间'http://www.galasoft.ch/mvvmlight'中没有EventToCommand标签。”

如果我使用 CallMethodAction 或 InvokeCommand Microsoft.Xaml.Behaviors.Wpf 效果很好,但我必须使用 EventToCommand 因为要将参数传递给 Command。

我应该怎么做才能解决这个问题? 谁能告诉我解决办法?

感谢阅读。

【问题讨论】:

    标签: wpf eventtocommand


    【解决方案1】:

    简短回答:不。

    MvvmLight 中的EventToCommand 类继承自System.Windows.Interactivity.TriggerAction&lt;T&gt;,不能添加到Microsoft.Xaml.Behaviors.EventTriggerActions 属性中。

    所以你的选择是:

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

    【讨论】:

    猜你喜欢
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多