This project has moved. For the latest updates, please go here.

Delegate Command, CanexecuteMethod gets never executed

Dec 9, 2011 at 10:33 AM

HI,

is there anything special to watch out for while implementing a Delegate Command? The Command itself is working fine but the associated CanExecuteMethod does not seem to be called.

TIA

-kinl99

Coordinator
Dec 10, 2011 at 9:07 AM
Edited Dec 10, 2011 at 9:08 AM

Hi,

If you want to use the CanExecute delegate then you have to:

1. Specify the CanExecute method in the constructor of the DelegateCommand.

Code extract from EmailClient.Applications / CreateEmailAccountController class:

nextCommand = new DelegateCommand(Next, CanNext);
…
private bool CanNext() { return emailAccountsViewModel.IsValid; }

2. Notify the command with RaiseCanExecuteChanged() when the CanExecute method might return a new value.

Code extract from EmailClient.Applications / CreateEmailAccountController class:

private void UpdateCommandsState()
{
    backCommand.RaiseCanExecuteChanged();
    nextCommand.RaiseCanExecuteChanged();
}

jbe

Dec 10, 2011 at 9:36 AM

Step 2 solved it. Thanks :)