originally posted by Laurent Bugnion: (link) - please comment at original post
The advantage of pushing very early software to the advanced users is that bugs are detected before too many people suffer from them, and features requests can be placed and implemented without pain. This is exactly what happened with the MVVM Light Toolkit V3 alpha 2.
This applies to the new “send with token” feature of the Messenger. When a recipient registers for a type of message, it can provide a token (any object). Then, when a sender sends a message, it can also provide the same token. The Messenger will only send the messages to those recipients who provided the same token when registering. This enables creating separate optimized communication channels between objects. The token can be any object, for example a string, a GUID, etc…
A silly mistake I made in the Messenger preventer simple values (such as an Integer) to be used as a token when sending a message. Simple values can be very valuable for this scenario, since a common reference is not needed to the token: It is simply a kind of contract that the sender and the receiver agree upon in advance. This is as decoupled as it gets, and yet enables a private channel of communication between two objects. Anyway, this mistake is corrected, and available in changeset 34855 on Codeplex.
A user on Codeplex required an additional feature in the EventToCommand behavior: Adding a way to get the EventArgs from the fired event to the invoked command. I tried to find a good way to implement that, and decided to make this an opt-in feature. The scenario is:
- if you set the new property PassEventArgsToCommand to true in the EventToCommand
- and you do NOT set the CommandParameter, nor the CommandParameterValue
- and you use a RelayCommand<EventArgs> as the data bound command
- then the parameter passed to the RelayCommand will be the EventArgs.
I believe that passing the EventArgs straight to the ViewModel is a bit overstepping the separation of concerns between the View and the ViewModel. However I do also acknowledge that there are cases where this can be useful, and so now it is possible. This feature is also implemented in changeset 34855 on Codeplex.
Sample applications on Codeplex
I took the occasion to upload some sample applications on Codeplex too.
- EventToCommand: This application demoes the feature of the same name, and is detailed in this blog post.
- CleanShutdown: This application shows a practical use for the Messenger, and a way to implement a clean shutdown that can easily be extended with additional components. More about this application here.
- RaiseCanExecuteChanged: This app shows how to use RelayCommands and more info about this sample is found in this blog post.
Remember to please comment at original post: (link)