-
Will Silverlight 4 ICommand support simplify using commands in Prism?
4 CommentsAs 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.
-
4 Comments:
Leave a comment
Your email address will not be published.

DotNetShoutout said on December 10, 2009:
Will Silverlight 4 ICommand support simplify using commands in Prism?…
Thank you for submitting this cool story – Trackback from DotNetShoutout…
Twitter Trackbacks for Damian Schenkelman’s Blog » Blog Archive » Will Silverlight 4 ICommand support simplify using commands in [southworks.net] on Topsy.com said on December 10, 2009:
[...] Damian Schenkelman’s Blog » Blog Archive » Will Silverlight 4 ICommand support simplify using … blogs.southworks.net/dschenkelman/2009/12/07/will-silverlight-4-icommand-support-simplify-using-commands-in-prism – view page – cached 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. [...]
Phil Steel said on December 10, 2009:
Hi Damian
Would you be able to email me the attached behaviors snippet as a zip file?
I’m behind a corporate firewall which is blocking the link to the code.
Many thanks,
Phil
Damian Schenkelman said on December 12, 2009:
Hi Phil,
I have sent you an email with the snippet attached.
I hope its useful,
Damian