Windows Phone 8.1 - MVVMLight - 为什么EventToCommad不起作用?

Dom*_*ikP 5 mvvm-light eventtocommand windows-phone-8 windows-phone-8.1

我无法在Windows Phone 8.1应用程序中使用EventToCommand.

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8"
Run Code Online (Sandbox Code Playgroud)

我也尝试使用assembly = GalaSoft.MvvmLight.Extras.WP81 ...

<controls:PivotItem Name="pivotItem">
<i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectionChanged">
        <cmd:EventToCommand Command="{Binding SelectServiceCommand}"
                            CommandParameter="{Binding SelectedIndex,                                 ElementName=pivotItem}"/>
    </i:EventTrigger>
    <!-- other stuff  -->
</i:Interaction.Triggers>
Run Code Online (Sandbox Code Playgroud)

我得到以下错误:

  • 成员"触发器"无法识别或无法访问.
  • XML命名空间'clr-namespace中的未知类型'EventTrigger':System.Windows.Interactivity; assembly = System.Windows.Interactivity'
  • 错误2在"交互"类型中找不到可附加属性"触发器"....

有谁可以帮助我吗?

Mal*_*tek 4

您的目标是 Silverlight 还是 WinRT(通用应用程序)之类的 Windows Phone 8.1?

如果您选择了第二个选项,那么在这篇博文中,MVVM Light 作者解释了缺乏对 EventToCommand 的支持 - 基本上在 WinRT 中已经存在类似于 EventToCommand - 行为的机制。