【问题标题】:How to use invokationCommandAction with MVVM Light v5?如何在 MVVM Light v5 中使用 invokationCommandAction?
【发布时间】:2014-10-20 14:39:05
【问题描述】:

我有一个目标是 .NET 4.5.1 的项目。我安装 MVVM Light nuget,经理安装 MVVM Light 5 版。

在这个版本中我不能使用 EventToCommand,我必须使用 incovationCommandAction,所以我需要在我的 axml 标题中添加这段代码:

xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"

这个代码添加一个命令到我的控件:

<interactivity:Interaction.Behaviors>
            <core:EventTriggerBehavior EventName="PointerPressed">
                <core:InvokeCommandAction 
                    Command="{Binding ShowPositionCommand, Mode=OneWay}"
                    InputConverter="{StaticResource MouseButtonEventArgsToPointConverter}"
                    InputConverterParameter="{Binding ElementName=LayoutRoot}" />
            </core:EventTriggerBehavior>
        </interactivity:Interaction.Behaviors>

但是,我收到一条错误消息,提示 core:EventTriggerBehavior 在 Microsoft.Xaml.Interactions.Core 中不可用。

问题出在哪里?我得到的例子from this link

是否可以在目标为 4.5.1 的项目中使用 MVVM Light v4.3?

谢谢。

【问题讨论】:

  • 这适用于 windows 8.1 吗?

标签: mvvm mvvm-light


【解决方案1】:

对于事件触发器,我使用以下代码 - 如果这对您有帮助,请告诉我。 (这是使用 MVVM Light 版本 5,针对 .NET 4.5)

xmlns:j="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"


<j:Interaction.Triggers>
        <j:EventTrigger EventName="PreviewKeyDown">
            <cmd:EventToCommand Command="{Binding SomeCommand}"> 
            </cmd:EventToCommand>
        </j:EventTrigger>
</j:Interaction.Triggers>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多