Ignore CanExecute

Topics: Prism v2 - Silverlight 3
Mar 13, 2010 at 2:42 AM

Hi All

I have attached a click.command to a button and also have an IsEnabled converted that is bound to a ValidationSumary control so that when there are validation issues, the button is disabled. Here is the code:

<Button Grid.Row="6" Margin="6" Content="Update Filters" Commanding:Click.Command="{Binding FilterSubmitCommand}" Width="150" 
                    IsEnabled="{Binding Path=HasErrors, ElementName=ValidationSummary1, Converter={StaticResource HasErrorsToIsEnabledConverter}}" />

The issue is that even though I have not bound to the CanExcecute event, when the click.command was added, the button is never disabled. it is conflicting with the CanExecute. is there someway to ignor CanExecute?

 

Nick

Developer
Mar 16, 2010 at 4:07 PM
Edited Mar 16, 2010 at 4:47 PM

Hi Nick,

The usual approach for enabling/disabling a button bound to a command is to use the CanExecute event (which internally manages the button’s IsEnabled property). You should call the RaiseCanExecuteEvent whenever a property involved in that validation changes, and put the validation logic for that button in the CanExecute method of the command. You can find an example of this usage in the Silverlight Commanding Quickstart, as well as the Silverlight Reference Implementation.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi