• Will Silverlight 4 ICommand support simplify using commands in Prism?

    Published by on December 7th, 2009 11:48 am under Composite Application Guidance for WPF & SL, p&p, Patterns & Practices, Prism-v2, Prism-v2.1, Silverlight, Silverlight 4 Beta

    4 Comments

    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

    Tags: , , , , , ,

    • Phil Steel

      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

    • http://blogs.southworks.net/dschenkelman Damian Schenkelman

      Hi Phil,
      I have sent you an email with the snippet attached.

      I hope its useful,
      Damian

Archives

Categories