Emulating ICommandSource in Silverlight 2

I recently discovered that Silverlight 2 has the ICommand interface, but does not have ICommandSource.  Basically, this means that you cannot easily execute a command when, say, a user clicks a button.  This is pretty strange to me, and renders Silverlight’s ICommand interface next to worthless.  If you’re an MVVM zealot like me, I’m sure you must see where I’m coming from here…

So, I corrected the situation.  You can now execute commands, pass them parameters, and even honor their CanExecute status, all via some attached property magic.  Read more about it, and download the source code, here.

7 Responses to Emulating ICommandSource in Silverlight 2

  1. Josh, you never seem to stop amazing me. I *thought* commanding was a missing feature to Silverlight after I read the MSDN docs on the SL ICommand interface. Thank you!

    -Jer

  2. Josh Smith says:

    No prob, Jer. Everything is missing until you create it! 😀

    Josh

  3. peteohanlon says:

    Nice work Josh. Clean implementation, but very annoying that it had to be left to the great Rock Star to bring it together – your mind should be on higher things.

  4. Josh Smith says:

    It’s all good, Pete. Working with Silverlight, you’re bound to get some dirt under your fingernails.

    Josh (a.k.a. the Great Rock Star) 🙂

  5. peteohanlon says:

    I’ve just been playing about with using the same control in WPF and Silverlight. I’m basically testing the limits to see where the two coincide and where design decisions need to be taken. As a simple test, I wrote a watermark textbox to work in both Silverlight and WPF, and hey presto – a control that works in both. I put the post up on my blog, but I’m going to be tidying it up because the default formatting in wordpress just gets in the way.

    I’ll be putting more information as and when I hit the limits.

  6. […] Smith on Emulating ICommandSource in Silverlight 2 and Putting Silverlight Commands to […]

  7. John "Z-Bo" Zabroski says:

    Slick. I wanted this and didn’t think there was a way to create it. I’m glad you’re here to make me feel dumb.. I can’t wait to stop supporting ext.js, but I’ve found the subset of wpf that SL2 supports to be underwhelming.

    Really want markup extensions ;0