Closed mrousavy closed 6 years ago
Automatically re-evaluate the RelayCommand::CanExecute(T t) function whenever the parameter t changes.
RelayCommand::CanExecute(T t)
t
Before:
ICommand LoginCommand = new RelayCommand<MyObject>(LoginAction, CanExecute); // ... bool CanExecute(MyObject parameter) { return parameter.SomeValue == true; } // ... public T MyObject { get => _myObject; set { Set(ref _myObject, value); LoginCommand.RaiseCanExecuteChanged(); // re-evaluate CanExecute(T) } }
After:
ICommand LoginCommand = new RelayCommand<MyObject>(LoginAction, CanExecute); // ... bool CanExecute(MyObject parameter) { return parameter.SomeValue == true; }
Possible approaches:
PropertyChanged
INotifyPropertyChanged
public event EventHandler CanExecuteChanged { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; }
??
c3951e4 fixed it.
Automatically re-evaluate the
RelayCommand::CanExecute(T t)
function whenever the parametert
changes.Before:
After:
Possible approaches:
PropertyChanged
if it's implementingINotifyPropertyChanged