如何在WP8.1中使用MVVM Light的事件触发器?

时间:2015-12-28 12:05:07

标签: windows-phone-8.1 mvvm-light

在WPF应用程序中,要使用MVVM Light的命令,我使用:

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>

但是在WP8.1中,我无法使用迭代性,因此我不知道如何使用触发器和EventToCommand。

感谢。

1 个答案:

答案 0 :(得分:2)

这样的东西?

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

<Interactivity:Interaction.Behaviors>
    <Core:EventTriggerBehavior EventName="PreviewKeyDown">
        <Core:InvokeCommandAction Command="{Binding SomeCommand}"/>
    </Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>

希望这有帮助。