Will Silverlight 4 ICommand support simplify using commands in Prism?

As I thought this is a question that could interest many people, instead of answering this question directly in the Prism codeplex forum I decided to create a short blog post and answer it here.

The answer is “kind of”. Silverlight 4 Beta, so far, only supports binding commands to controls that inherit from ButtonBase (Button and HyperlinkButton), as you can read in Tim’s and Mike’s posts.
Therefore, if you are using Prism, these are the things that you will not need any more, and those that you will:

No longer necessary

ButtonBaseCommandBehavior and Click classes from the CompositePresentationSilverlight assembly. As these are used to hook the command and the click event through XAML, you can bypass this by using the new command support.
<Button Content="Save" Command="{Binding Path=SaveOrderCommand}"/>

Still necessary

As there is not an actual implementation of the ICommand interface, the DelegateCommand and CompositeCommand are still useful. Also, as controls other than Buttons do not have the possibility to bind their events to commands in the ViewModel, using attached behaviors is a good approach. You can use this code snippet to simplify the work.

Wrapping up

I hope this helps clarify this topic a bit, and if you have any doubts drop by the Codeplex forum and ask away (if you are shy you can always leave me a comment).

In case you want a working sample, I have made a couple of changes to the Commanding Quickstart to use the Command property instead of Prism’s attached behavior. You can find it here. The code is provided “AS IS” with no warranties and confers no rights.

Shout it

kick it on DotNetKicks.com



2 Comments

Leave a Reply