IdentityMine

| Tags: Laurent Bugnion, Silverlight, WPF

originally posted by Laurent Bugnion: (link) - please comment at original post

Update (11/14/2009): The sample application is available as a zip file, and I also published the Silverlight version to be executed directly in your browser.

l1

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.

Bug correction

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.

New feature

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.

I also updated the sample application which can be downloaded here, or from Codeplex (see below). The Silverlight version of the sample application can also be run here.

l2

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.

Happy coding!!

Remember to please comment at original post: (link)

Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on TumblrEmail this to someoneDigg thisFlattr the authorShare on StumbleUpon

Trackbacks/Pingbacks

  1.  얼바인사랑의교회-에버그린 북카페 - 00089 목적이 이끄는 삶