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

IsEnabled property of RelayCommand not showing expected behavior to enable and disable the control on changing that property

May 1, 2011 at 7:49 PM

Here is solution that I came up with:

1) RelayCommand class declaration could be as:

public class RelayCommand<T> : ViewModelBase, ICommand

2) Implementation of IsEnabled property could be as follows:

        public bool IsEnabled
            get { return _isEnabled; }
                if (value != _isEnabled)
                    _isEnabled = value;


3) Lastly you need to bind the IsEnabled property in xaml as follows:

IsEnabled="{Binding Path=SearchCommand.IsEnabled}"

May 4, 2011 at 3:25 AM

When you bind to an ICommand, it automatically takes care of the IsEnabled property. Don't bind that yourself.

Return your condition from the canExecute lambda expression (the second, optional constructor parameter). If you need to refresh the enabled state, call RaiseCanExecuteChanged on the command object.