2014-10-20 48 views
0

我有一个项目,其目标是.NET 4.5.1。我安装MVVM Light nuget,管理器安装MVVM Light的第5版。如何在MVVM Light v5中使用invokationCommandAction?

在这个版本中,我不能使用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> 

不过,我得到的是说核心的错误:EventTriggerBehavior不可用Microsoft.Xaml.Interactions.Core。

这是问题所在?我得到的例子from this link

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

谢谢。

+0

这是否适用于Windows 8.1? – aggietech 2014-10-20 20:23:09

回答

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>