Windows Phone 8.1 - MVVMLight - Why is EventToCommad not working?
Asked Answered
C

3

5

I am not able to use EventToCommand in my Windows Phone 8.1 App.

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8"

I tried it also with 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>

I get the following erros:

  • The member "Triggers" is not recognized or is not accessible.
  • Unknown type 'EventTrigger' in XML namespace 'clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity'
  • Error 2 The attachable property 'Triggers' was not found in type 'Interaction'. ...

Can someone help me please?

Cancellation answered 29/4, 2014 at 9:26 Comment(0)
R
4

Are you aiming at Silverlight, or WinRT (Universal Apps) kind of Windows Phone 8.1?

If you have chosen the second option, then in this blog post MVVM Light author explains the lack of support for EventToCommand - basically in WinRT there's already a mechanism similiar to the EventToCommand - Behaviours.

Rangoon answered 29/4, 2014 at 10:17 Comment(1)
Do you know the solution regarding the first situation (targeting Silverlight 8.1)? I created a new WP 8.1 project and added mvvm light trough NuGet but "EventToCommand" from "GalaSoft.MvvmLight.Command" was not found. Thanks!Kristenkristi
A
3

Windows Phone 8.1

Windows 8.1 Behavior SDK: How to use InvokeAction with InputConverter to pass arguments to a Command

Microsoft has developed it's own EventToCommand functionality. It's located in Behaviors SDK. Someone on stackoverflow told to get this SDK via Nuget. If you can't find the package in NuGet - get it in Add reference dialog.

enter image description here (My "Add reference" dialog may differ from original because of Productivity Power Tools extension)

Here is example of simple usage:

<ListBox ItemsSource="{Binding Persons, Mode=OneWay}" 
         SelectedItem="{Binding SelectedPerson, Mode=TwoWay}">
    <interactivity:Interaction.Behaviors>
        <core:EventTriggerBehavior EventName="SelectionChanged">
            <core:InvokeCommandAction Command="{Binding DisplayPersonCommand}" />
        </core:EventTriggerBehavior>
    </interactivity:Interaction.Behaviors>
</ListBox>
Anyhow answered 22/12, 2014 at 10:16 Comment(0)
A
1

When upgrading my WP8.0 app to use MVVMLight 5.0+ disabled the EventToCommand behavior, my search for a solution brought me to this blog post that provided source code for implementing a Custom Command Action that will pass the event args as the parameter. Implementing the code returned my app to working order!!

Hopes this helps you out :D

Ascension answered 18/12, 2014 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.