Disabling Commanded Buttons

Aug 26, 2012 at 5:16 AM

Suppose I created a button bound to a DelegateCommand, this DelegateCommand is defined with a CanExecute and an OnClick method.

I suppose that if CanExecute returns false, then the associated button should be disabled, but it's not the case.

What else do I have to do?

Silverlight 5 and Prism 4.1



Aug 27, 2012 at 2:01 PM
Edited Aug 27, 2012 at 2:01 PM

Hi Rafael,

I believe, one thing you could consider when using a DelegateCommand, is that when the CanExecute status changes, the view model can notify this change by calling the RaiseCanExecuteChanged method on the DelegateCommand object. This causes the CanExecuteChanged event to be raised causing that any controls in the UI that are bound to the command will update their enabled status to reflect the availability of the bound command. Perhaps, this could be related to your behavior.

You could find more information about the use of DelegateCommands and and how to associate them with controls in the view in the following section of the Prism documentation:

Also, for an example of how you can implement this, you might find the Commanding QuickStart provided with Prism interesting.

I hope you find this helpful,

Agustin Adami

Aug 27, 2012 at 7:51 PM

Thank you Agustin.