CommandBehaviorBase<T> explanation required

Topics: Prism v2 - Silverlight 4
Sep 23, 2010 at 6:54 PM
Edited Sep 23, 2010 at 6:59 PM

I'm new to PRISM and silverlight. And I'm not able to understand the real deal about the CommandBehaviorBase<T> extensions. I've been reading blogs on this topic for two days yet I'm unable to make any bigger and clearer picture out of it. The more I read about it the more unanswered questions raises. So can anyone post some good link[s] that can explain the the very basic concepts about this Class. I know we need it for creating custom behaviors. What I want to know is;

  • what differentiate this from Behavior<T> which was part of SL3
  • Is it mainly related to WPF?
  • Is there any other alternate for this in PRISM for silverilght?
  • under what scenarios I'd need it?
  • Can I implement my behaviors for "FrameworkElement"? should that work for every control or do I need to do that for every different control?
  • And can I create behavior using this for some properties of the controls as well if yes then how can I do that? Because most of the blogs I've gone through only talk about Events somehow
  • Last but not the least how can I debug this component, as I've made couple of hello world kind of behaviors for my custom grid but it doesn't work but thing is they don't even flash any kind of error whatsoever.

your every answer will highly appreciated. Thanks in advance.


Sep 23, 2010 at 7:38 PM



Nice to see that you started using Prism. In the latest drop, there is a documentation section dedicated specifically to this topic. So, for more information I would recommend to you to download the latest drop from here, so you could take a look at the following documentation section (this document hasn’t been published online yet):

  • Silvelight 3 Command Support (new)

I think this document could cover most of your questions.

I hope this helps,

Fernando Antivero

Sep 24, 2010 at 4:45 PM

Hi again,
thanks fantivero for your timely help, this makes much more sense now.

I've managed to implement couple of commandbehaviors for couple of controls. One of which I'd like to ask inquire about which is SelectionChanged of a datagrid. Can you share some pointers about how can I get something like RowObject,of my datagrid that can let me customize my datagrid control in general like different cells or selected rows or something like that while implementing CommandBehaviorBase<T> type. I really can't see anything of that sort within my given delegate functions for the events in the behaviors. I assume It might be bit off topic as its not directly related to PRISM  but I'd be really grateful to you once again if you can just shed some light on this too.

Sep 24, 2010 at 6:18 PM


Nice to see that you find the documentation interesting. Based on my understanding your want to create a CommandBehavior for the SelectionChange of your grid. Additionally, this command should pass as argument the row values.

Therefore, for achieving your scenario, I would recommend you to take a look at the Microsoft.Practices.Prism.Commands.Click class under the Prism.Silverlight or Prism.Desktop projects, since this implementation uses the ButtonBaseClickCommandBehavior and also supports CommandParamaters. So your implementation might be similar to this.

In addition in the documentation Silvelight 3 Command Support (new) there is a section related to this named Providing a Command Parameter Value

On the other hand, you could check the reference implementations applications, since it might be helpful to see how this commands are used.

I hope that this helps,

Fernando Antivero