WP8 MvvmLight namespace is missing and EventToCommand does not exist

I only use the MVVM Light libraries (from the Nuget package) in my Windows Phone 8 project, and I want to use EventToCommand in ToggleSwitch . I have these lines of code:

 <toolkit:ToggleSwitch x:Name="LockSwitch" IsChecked="{Binding IsLock, Mode=TwoWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="Toggled"> <Command:EventToCommand Command="{Binding DataContext.NavigateToArticleCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" /> </i:EventTrigger> </i:Interaction.Triggers> </toolkit:ToggleSwitch> 

The problem is that VS is showing errors:

Error 1 The name "EventToCommand" does not exist in the namespace "CLR names: GalaSoft.MvvmLight.Command; assembly = GalaSoft.MvvmLight.Extras.WP8".

Error 2 Type "Command: EventToCommand" not found. Confirm that you are missing a build link and that all build links have been built.

Error 3 The tag 'EventToCommand' does not exist in the XML namespace of the CLR names: GalaSoft.MvvmLight.Command; assembly = GalaSoft.MvvmLight.Extras.WP8 '.

I have the lines above in the Styles.xaml file, which is a ResourceDictionary and ToggleSwitch is part of a DataTemplate . I use this library in the MvvmLight library:

 xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8" 

What happened? Why am I getting this error? I tried to use Google, but I could not find a solution.

+5
source share
2 answers

The link you use to enable the command is incorrect. Correct link

 xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform" 

There is a trick to getting this link without writing a single line of code.

Once you have downloaded the nvet MvvmLight package, compile your project and open your xaml file in Expression Blend.

Then click the Assets icon on the left toolbar (bottom) and start typing "eventtocommand" (see the figure below).

enter image description here

Once you see EventToCommand in the Assets panel, drag it on top of your ToggleSwitch . It! The link will be added to your xaml automatically, as well as the actual command code.

+5
source

Why not use the Microsoft.Behaviors SDK ? (links, adding links, extensions, sdk behavior) Not sure, but I think EventTrigger and mvvm light EventToCommand now deprecated (due to sdk behavior).

Sample code with Behaviors.SDK:

 xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:core="using:Microsoft.Xaml.Interactions.Core" <toolkit:ToggleSwitch x:Name="LockSwitch" IsChecked="{Binding IsLock, Mode=TwoWay}"> <interactivity:Interaction.Behaviors> <core:EventTriggerBehavior EventName="Toggled"> <core:InvokeCommandAction Command="{Binding command}" CommandParameter="{Binding param}"/> </core:EventTriggerBehavior> </interactivity:Interaction.Behaviors> </toolkit:ToggleSwitch> 
0
source

Source: https://habr.com/ru/post/1208839/


All Articles