MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

Update (11/14/2009): I updated EventToCommand with a new feature: You can now pass the EventArgs of the fired event to the invoked command. See this post for more explanations.

Here is another early release of the MVVM Light Toolkit V3 (Alpha 2). I decided to release gradually and early as soon as a new part of this new version is ready, to allow advanced users to install, test and give feedback about the new features. If you haven’t seen it yet, the features available in V3 Alpha 1 are described in a previous article. There will be a few more alphas before I make a V3 release, which means more good things are a-coming ;)

Usual disclaimer: Alpha releases are not feature complete (meaning that APIs may change) and it is very possible that there are bugs in the code. Use with care and give feedback if something is not working, thanks!!

EventToCommand behavior

The new feature available in V3 Alpha2 is called EventToCommand and is a Blend behavior. These pieces of code are optimized for Expression Blend, but can also be added directly in XAML, as we will see in this article.

EventToCommand is used to bind an event to an ICommand directly in XAML.

Note: Even though Expression Blend facilitates the usage of EventToCommand, it is not a prerequisite. EventToCommand can be used even if Expression Blend is not installed on your system, or on your users’ system.

Credits, History

This behavior reuses much code from the Expression Blend sample behavior named InvokeDataCommand. I want to give props to the Expression team for creating and publishing these great samples. This would not have been possible without the work put into these samples. I want to especially thank Pete Blois and Jeff Kelly of the Expression team for their help.

I also want to thank Rishi, the creator of the nRoute toolkit, for the interesting discussions and a couple of ideas that I implemented in EventToCommand.

If you are already using InvokeDataCommand, the new EventToCommand behavior brings the following additional features:

  • WPF / Silverlight compatibility: The WPF version of the Expression Blend sample behavior InvokeDataCommand has a bug that prevents it to work (the Silverlight version runs fine though). The bug is corrected in EventToCommand, and both versions run well.
  • CommandParameter is bindable. You can bind this property, for example, to the value of a slider, the content of a TextBox, or any other property that is accessible to a data binding.
  • Disabling the attached control: If the IsEnabled property is available for the attached element, you can opt-in to automatically disable the element if the Command’s CanExecute method returns false. This is dynamic, i.e. if the value of CanExecute changes, the element will be disabled/enabled.
    • In Silverlight, this is valid for all Controls.
    • In WPF, this is valid for all FrameworkElements (Panels, Shapes, Controls, etc…).
    • Note: By default, the element will not be disabled/enabled automatically. Since one element can have multiple EventToCommand behaviors added to link multiple events to commands, you probably want only one or two of these to affect the IsEnabled property. This can be turned on by using the MustToggleIsEnabled property, which can be either set in XAML (see below) or databound to a boolean value (checkbox, etc…).

Source code, Binaries

The source code is available on the Codeplex page.

The binaries can be found here.

Features, Usage

EventToCommand is a behavior that can be added to any FrameworkElement. This can be a Rectangle, an Ellipse (in fact, any shape), an Image, any Control (Button, Slider, CheckBox, RadioButton, and many many others) etc. In short: If you can add an element to your UI, you can probably add EventToCommand to it.

For more information about ICommand (and their MVVM Light implementation, RelayCommand), read this article. You can bind any event to any command. Typically, you will use this to link an element’s event to a command defined in a ViewModel class. For more information about the ViewModel pattern in WPF and Silverlight, this page will help you.

In Expression Blend:

Adding an EventToCommand to any element in Expression Blend is super easy thanks to the visual support.

  • Right click on the References folder and select “Add Reference”.
  • Add a reference to the MVVM Light DLLs. You need two: GalaSoft.MvvmLight.dll and GalaSoft.MvvmLight.Extras.dll. In addition, you need the System.Windows.Interactivity.dll which contains the base code for all behaviors.
    You can download the DLLs needed here. 
  • Open your project in Expression Blend, and build it to make sure that everything is working fine.
  • Locate the element on which you want to add a command in the Objects and Timeline panel.
  • Open the Assets panel and find the Behaviors category.
    You can also find behaviors in the Asset library, which is the last button on the bottom of the toolbar.
FliCA4
  • Drag the EventToCommand behavior on the element you selected before in the Objects and Timeline panel.
  • With the EventToCommand selected, select the Properties panel.
  • Select the event you want to handle.
  • In the Miscellaneous section, bind the EventToCommand to the ICommand you want to execute when the event is fired.
    If you use the MVVM pattern, you probably want to use an ICommand (for example a RelayCommand) located in the ViewModel that is set as the DataContext for your window/page.
    In WPF, you can also enter a value, for example ApplicationCommands.Save. In that case, you must set a CommandBinding.

Fli249C

  • If you want to pass a parameter to the ICommand, you can set the CommandParameter property. You can data bind CommandParameter to something (for example the Text property of a TextBox, etc…). If you want to set a hard coded value ) for example “Hello world”, you need to set CommandParameterValue in the XAML editor (see the “Caveat” section below).

FliD557

  • Finally, if you want the attached element to be disabled depending on the ICommand.CanExecute method, set the MustToggleIsEnabledValue property to True. You can also use MustToggleIsEnabled to data bind this property to something else (for example a CheckBox’s IsChecked property) (see the “Caveat” section below).
    • In Silverlight, this will only work on Controls. Use the VisualStateManager to modify the appearance of the disabled control.
    • In WPF, any FrameworkElement can be disabled. Use the Triggers panel to modify the appearance of the FrameworkElement when it is disabled.

In XAML

Using the XAML editor, follow the steps to add an EventToCommand to an element.

  • Add a reference to the MVVM Light DLLs. You need two: GalaSoft.MvvmLight.dll and GalaSoft.MvvmLight.Extras.dll. In addition, you need the System.Windows.Interactivity.dll which contains the base code for all behaviors.
    You can download the DLLs needed here. 
  • Add an xmlns for the following namespaces:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
  • Add the EventToCommand to the desired element (in this example, a Rectangle) with the following XAML code:
    This presupposes that the DataContext of your page/window is set to a ViewModel containing the TestCommand command, as is usual in the MVVM pattern.

<Rectangle Fill="White"
           Stroke="Black"
           Width="200"
           Height="100">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseEnter">
            <cmd:EventToCommand Command="{Binding TestCommand,
                                          Mode=OneWay}"
               CommandParameter="{Binding Text,
                                  ElementName=MyTextBox,
                                  Mode=OneWay}"
               MustToggleIsEnabledValue="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Rectangle>

Listening to events on other elements

Because EventToCommand derives from System.Windows.Interactivity.TriggerAction<T>, it has a property named SourceName. With this property, you can attach EventToCommand to an element, but listen to events on another element. I didn’t explicitly forbid this in the code, but I would recommend against it. I think that it creates confusing code that can easily be broken. The best is probably to always listen to events on the attached element itself, and leave SourceName empty.

Small caveat

Because of limitations in the Silverlight framework (specifically, the fact that data bindings can only be applied to a FrameworkElement), I had to resort to a small trick to make CommandParameter and MustToggleIsEnabled bindable. You will see in the code that there are four properties:

  • CommandParameter:
    • In Silverlight, used to data bind CommandParameter.
    • In WPF, used either for data binding or for hard coded values.
  • CommandParameterValue:
    • In Silverlight and in WPF, used for hard coded values only.
  • MustToggleIsEnabled:
    • In Silverlight, used to data bind MustToggleIsEnabled.
    • In WPF, used either for data binding or for hard coded values.
  • MustToggleIsEnabledValue:
    • In Silverlight and in WPF, used for hard coded values only.

In short, if you don’t care about Silverlight compatibility for your XAML code, you can always use CommandParameter or MustToggleIsEnabled in WPF, either for data binding or for hard coded values. If you want to share your XAML between a Silverlight and a WPF application, then you should respect the rules above, or else you will get exceptions in Silverlight when the XAML is being parsed.

Demo application

The demo application shows multiple usages of the EventToCommand behavior. The application runs in Silverlight and in WPF. Feel free to download the code and play with it to learn how to use EventToCommand! The Silverlight version of the sample application can also be executed directly in your web browser.

  • Binding a Button’s Click event and a Rectangle’s MouseEnter event to a simple RelayCommand.
  • Binding a Button’s Click event and a Rectangle’s MouseEnter event to a RelayCommand with a data bound parameter.
  • Binding a Button’s Click event and a Rectangle’s MouseEnter event to a RelayCommand with a hard coded parameter.
  • Binding a Button’s Click event and a Rectangle’s MouseEnter event to a RelayCommand and disabling them depending on the parameter’s value.
    Note: In Silverlight, Rectangles cannot be disabled.
  • Passing the EventArgs of a fired event to the invoked command.
    Note: This feature was added after V3 alpha 2 was released. See this post for more information.

License

MVVM Light Toolkit is distributed under the MIT License. This license grants you the right to do pretty much anything you want with the code, but don’t come crying if you break something (the exact wording is found here). Some parts of the GalaSoft.MvvmLight.Extras DLL are licensed under the MS-PL license.

 

Print | posted on Thursday, November 05, 2009 2:57 AM

Feedback

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Laurent Kempé at 11/5/2009 3:19 AM Gravatar
You did it again! Congrats Laurent for this GREAT step :)

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by thesiteman at 11/5/2009 4:05 AM Gravatar
we are not worthy...we are not worthy...we are not worthy...

Thanks and Great job...this is going to be awesome!

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by bhrnjica at 11/6/2009 12:56 AM Gravatar
Great work,
EventToCommand works great in VS2010 beta2 as well.

# Great Job!

left by Dan Wahlin at 11/6/2009 5:25 AM Gravatar
Great stuff Laurent! I haven't been a fan of commanding in Silverlight at all since it was so limited (thinking of Prism) without writing some custom code. Your solution lets me handle all the events I have to deal with nicely...well done!

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Kuba at 11/9/2009 9:36 AM Gravatar
On Codeplex there is apparently a file missing (It's in the solution but not in repository):

After checkout from svn:
\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras\Command\EventToCommand.WPF.cs' could not be opened

# I love it!

left by Kuba at 11/9/2009 9:57 AM Gravatar
Just got the binaries from the link in the article. Your Toolkit is a joy to use. Simple yet powerful, and everything just works, EventToCommand is great!

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Martin Hinshelwood at 11/11/2009 12:16 AM Gravatar
Looks fantastic :)

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by P.M. Goupil at 11/23/2009 10:27 PM Gravatar
J'ai un problème avec "EventToCommand Command" dans un DataTemplate. Un même bouton qui fonctionne avec la commande 'SimpleCommand' dans une page ne fonctionne plus s'il est déplacé dans un DataTemplate.
(MVVM Light Toolkit V3 Alpha 2).
Cordialement

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Laurent at 11/24/2009 10:23 PM Gravatar
Hello,

Je viens d'essayer ici et ca fonctionne, avec le template dans les resources locales, et aussi dans un ResourceDictionary. Peut-etre un problem de DataContext? Envoie moi ton projet (laurent (at) galasoft (dot) ch) et je regarde volontiers.

Amities,
Laurent

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Olivier at 1/8/2010 11:28 PM Gravatar
Merci Laurent pour ce super boulot.
MVVM Light est de loin ma lib préférée, ton approche pragmatique est la bonne.
Just hâte de voir une doc qui se tient :-) Mais c'est toujours le plus dur à boucler !
(mais ça serait vraiment mieux pour communiquer sur ton toolkit, là c'est un peu éparpillé et c'est vraiment trop fait pour les geeks alors que le toolkit est simple à utiliser et qu'il mérite d'être diffusé et utilisé largement. Je peux te donner un coup de main si tu veux... )

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Laurent at 1/9/2010 12:55 AM Gravatar
Merci pour les mots sympas, ca fait plaisir. Oui, la doc, je sais. Comme je suis en train d'ecrire mon nouveau livre sur Silverlight 4, pas trop de temps libre... cela dit, si tu veux ecrire des articles, je suis ravi de les publier sur le site du toolkit!
http://www.galasoft.ch/mvvm/getstarted/#blogs

Amities,
Laurent

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Nasir at 1/28/2010 8:00 AM Gravatar
This is a great toolkit and am having fun with it. Except one issue, I tried EventToCommand behavior in Silverlight 4, seems like its not firing the command. Have you seen or tested this? Do we have to do anything different in SL4? Thanks for all your work!

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Laurent at 1/28/2010 8:58 AM Gravatar
Hi,

Yes it was tested in SL4 and should work fine. Make sure that you are using the SL4 DLLs and not the SL3. Using the SL3 DLLs, it will build but will not execute correctly.

When I release the final V3 version, I will change the names of the DLLs to make it more obvious which one if for which version of the framework.

Let me know if this solves the issue,
Thanks,
Laurent

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Ilyasse at 4/1/2010 2:48 AM Gravatar
Vos librairies sont vraiment très utiles. Mais j'ai un problème à l'exécution lorsque je veux binder une simple commande Click dans ma View à mon ViewModel.

J'ai le message suivant

La propriété pouvant être attachée 'Triggers' est introuvable dans le type 'Interaction

<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GM:EventToCommand Command="{Binding SimpleCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>

Vous savez pourquoi ? J'utilise les dll pour la version 4 de Silverlight. Merci d'avance...

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by pM at 4/2/2010 2:15 AM Gravatar
Bonjour...Je kiff grave aussi ce toolKit. 2 choses:
- Pour le post précédent (Ilyasse): je confirme le meme problème. Je dois faire référence à .Interactivy d'une version inférieure
- Rien ne passe sur un SelectionChanged pour le code suivant:
<ComboBox Width="200" ItemsSource="{Binding Path=Themes}" Height="25" SelectedValuePath="Theme" SelectedValue="{Binding Path=CurrentNote.Theme, Mode=TwoWay}" SelectionChanged="ComboBox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="5" BorderThickness="1" BorderBrush="{Binding Path=ForeColor}">
<StackPanel Background="{Binding Path=BackColor}" Height="20" Margin="0">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Width="200" Text="{Binding Path=Name}" Foreground="{Binding Path=ForeColor}"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ComboBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding SelectChangeCommand}"></cmd:EventToCommand>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
Merci d'avance

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Jean Marc at 4/2/2010 5:52 AM Gravatar
Bonjour Laurent,

Jusque quelques mots pour dire un grand merci.
J'ai passé beaucoup de temps à essayer de comprendre le 'pattern' MVVM jusqu'à présent sans succès.

Finalement et pour être bref, MVVM Light toolkit: Framework + Snippets + Exemples = en 1 mot, SO EASY !

Bonne continuation!

PS:superbe présentation au MIX10!

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Miguel Angel Santiago at 4/11/2010 10:09 PM Gravatar
Dear Laurent,

Thank you very much for this great functionality EventToCommand.

I was trying to apply it on the events from the MS Surface, but I am having troubles to catch the actual events from Surface Controls (I guess they inherit from FrameworkElement). For instance:

Let the traditional method be:

<s:SurfaceButton s:Contacts.ContactDown="OnContactDown"
</s:SurfaceButton>

now I change to:

<s:SurfaceButton>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ContactDown">
<cmd:EventToCommand Command="{Binding ContactCommand, Mode=Default}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</s:SurfaceButton>

However, it does not raise the Command. I've checked that my code is right by simply replacing the event ContactDown by the traditional Click.

Could you tell how could I make work the events of Surface into Commands of the MVVM?

Thank you very much in advance.

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Miguel Angel Santiago at 4/12/2010 12:42 AM Gravatar
Sorry, there was a mistake in my code. It is not s:SurfaceButton what I really meant, but another object which not includes ContactDown as native event. For instance: a rectangle which aims to catch the ContactDown.

Let me make it clearer:

<Rectangle s:Contacts.ContactDown="OnContactDown"
</Rectangle>

ant the objective would be:

<Rectangle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="s:Contacts.ContactDown">
<cmd:EventToCommand Command="{Binding ContactCommand, Mode=Default}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</s:SurfaceButton>

In the meanwhile, I've found out an interesting solutiong from: http://bit.ly/aWcEOS

Therein, it suggests to code a RouteEventTrigger to solve the recovery of the EventName from Reflection. I've updated the code like this and it works:

<Rectangle>
<i:Interaction.Triggers>
<mvvmjoy:RoutedEventTrigger RoutedEvent="s:Contacts.ContactDown">
<cmd:EventToCommand Command="{Binding ContactCommand, Mode=Default}"/>
</mvvmjoy:RoutedEventTrigger>
</i:Interaction.Triggers>
</s:SurfaceButton>

In any case, if you suggesst any other solution, it is also welcome.

Thank you very much.

# EventToCommand does not exist in namespace

left by Dan at 4/27/2010 8:23 AM Gravatar
I get the following error when trying to use in Windows7, VS10.

The tag 'EventToCommand' does not exist in XML namespace 'clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras'.

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Mike Lockyer at 5/17/2010 7:03 AM Gravatar
I am trying to use the EventToCommand to provide a MVVM solution to the SElectItem item issue as identified by
https://www.west-wind.com/Weblog/posts/567249.aspx

But with no luck

Can I set CommandParameter to the selected item in a list box

Thanks

Mike

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Laurent at 5/20/2010 9:01 PM Gravatar
Hi Mike,

For SelectedItem (singular), use a data binding to a property on the target object (typically this is a ViewModel).

For SelectedItems (plural), see http://blog.galasoft.ch/archive/2010/05/19/handling-datagrid.selecteditems-in-an-mvvm-friendly-manner.aspx

Cheers,
Laurent

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Gary Howlett at 7/15/2010 12:05 AM Gravatar
How can I use EventToCommand on a TreeView when I wish to actually attach to TreeViewItem.Expanded?

Thanks

Gary

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Blobi at 8/15/2010 9:36 PM Gravatar
Bonjour,

Est-il possible de lier un Behavior ajouté à une gestion d'événement EventToCommand ?

Je pose cette question car j'ai ajouté la gestion du
double click sur mon datagrid par un Behavior et j'aimerai gérer cette événement avec les commandes.

Merci pour votre aide

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Nabeel at 8/20/2010 4:59 AM Gravatar
Hi Laurent,

Is it possible to pass more than one parameter to the command and is it possible to pass properties of EventArgs instead of passing the whole EventArgs ?

Regards,
Nabeel

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Someone at 9/19/2010 9:41 PM Gravatar
I have a weird problem with RelayCommand and MustToggleIsEnabled on Windows Phone 7: when the bound event occurs (its a button click) the canExecute Func<bool> is called before the actual execute Action. Because of this the IsEnabled state of my button reflects the state of the underlying instance before the action is beeing executed.
On the other hand, i am sure it was working before. Dont know what went wrong.

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Someone at 9/19/2010 9:46 PM Gravatar
Maybe this behaviour is correct. But when MustToggleIsEnabledValue is true shouldnt the canExecute Func<bool> get called again after the execute Action was called? At least, my button remains enabled and i don't know whats wrong :-)

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Anonymous at 11/18/2010 10:45 PM Gravatar
Is it possible to bind custom events to teh command using "EventToCommand" ? I am currently evaluating the feasibility of using MVVMLight of our product and this is one think I am stuck up with. Also do you think MVVMlight will work better for CustomControls as well.. Any help is much appreciated..Thanka !

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Alberto at 11/23/2010 12:23 AM Gravatar
Hi,

I am new with MVVM and I was playing around with this framework. I create a small application and everything is working correctly when I only want to send one parameter to the command. But do you know how can I send more than one parameter to the command?

For example with a form with 3 or 4 text-boxes??

Thanks.
Alberto

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by aappddeevv at 12/4/2010 7:36 PM Gravatar
Similar to the comment above about TreeViewItems, I need to attach the EventToCommand to TreeViewItems being generated by a TreeView in order to capture the mouse double click event and turn it into a "Open in editor" command. How to attach this in XAML to the ItemContainerGenerator's output? Or will this need to be done in code-behind?

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Randy at 12/9/2010 9:25 PM Gravatar
Hi,

Thank you for the excellent work! We are using MVVM Light in our applications and it has helped tremendously.

My question is related to EventToCommand behaviors: SInce it is possible to create multiple EventToCommand elements for a single EventTrigger element in XAML, is there a way to specify the order in which the EventToCommand elements are processed (i.e. order in which the commands are executed)? My guess is that they will be executedi n the order in which they appear in the XAML, but I wasnt' sure.

Thanks again,
Randy

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Jean-Pierre Fouche at 1/18/2011 12:23 PM Gravatar
Hi Laurent,
Thank you for your great work.
I am trying to use the WPF extras, but it won't load the System.Windows.Interactivity.dll.

Any ideas why this may be the case? I have tried using the downloaded dll as well as the one available from the GAC.

Visual Studio 2010 (.NET 4, WPF).

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Alex at 1/19/2011 5:09 AM Gravatar
Hi Laurent,

I am trying to use the EventToCommand but I am getting the following error:

"The tag 'EventToCommand' does not exist in XML namespace 'clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4'"

I've added the reference to "C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\Silverlight4\System.Windows.Interactivity.dll" but still the error is there.

Any ideas on why this may be occurring ?

Thanks for your help
Regards
Alex

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Laurent at 1/19/2011 8:11 AM Gravatar
Did you reference GalaSoft.MvvmLight.Extras.SL4.dll?

Laurent

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Alex at 1/20/2011 6:12 AM Gravatar
Yes, I did. Strangely, in design time IntelliSense sense picks up EventToCommand when I type cmd:
However, I get "The tag 'EventToCommand' does not exist.." error when compile my app.

Thank you,
Alex

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Madhur at 2/13/2011 5:23 PM Gravatar
I want to pass XamDataTree's SelectedItems from one view model to another. Do you think this is a good idea? and if yes how to do that? I see examples of simple parameters like TextBox.Text passed as parameters. Any help will be appreciated.

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Alex at 3/7/2011 5:58 AM Gravatar
Hi Laurent,

I've realised lately that System.Windows.Interactivity.dll from MVVM Light Toolkit clashes somehow with the one from Microsoft.
I added the reference to "C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\Silverlight4\System.Windows.Interactivity.dll" assembly using Add Reference/Browse option in VS 2010.
When I check its properties it shows reference to "C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries\System.Windows.Interactivity.dll"

I couldn't figure out what else I can do to force reference to the "C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\Silverlight4\System.Windows.Interactivity.dll"?

Thanks for your help
Regards
Alex

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Daniel Freire at 3/9/2011 6:21 PM Gravatar
I discovered the problem:

Problem:

The tag 'EventToCommand' does not exist in XML namespace 'clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras'.

Solution:

What is happening is that your dll is named differently, when you download the binary dll site is for WPF, Silverlight and Windows phone, and each has a different nomenclature for example to WPF is GalaSoft.MvvmLight.Extras.WPF4.dll and xaml pointing to this assembly=GalaSoft.MvvmLight.Extras assembly that does not exist then in the case of WPF should look like this:

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


I'm from Brazil
Original message in Portuguese translated into English in google.

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Laurent Bugnion at 3/9/2011 11:56 PM Gravatar
@Alex: This is the same DLL (or maybe a slightly different, but compatible version). I provide it as part of MVVM Light for convenience only, so that the user does not have to install the Blend SDK to use EventToCommand.

Studio tends to replace the reference with the one to the Blend SDK if it is installed. This shouldn't cause an issue.

Cheers,
Laurent

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Sven De Baets at 3/10/2011 2:15 PM Gravatar
Daniel,

Had the same problem when upgrading from SL3 to SL4.

You're probably referencing the wrong version of System.Windows.Interactivity. The assembly version should be 4.0.5.0. Just take the one from the MVVM Light Toolkit package on CodePlex.

Gr,

Sven

# re: MVVM Light Toolkit V3 Alpha 2: EventToCommand behavior

left by Sven De Baets at 3/10/2011 2:18 PM Gravatar
Typo ... my last message was ment for Alex, not Daniel.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: