2014-10-20 51 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>