I have a Command
property, with this definition in the view model:
public RelayCommand SaveCommand => new RelayCommand(OnSave, CanSave);
whenever the ErrorsChanged
of the INotifyDataErrorInfo
is fired, RaiseCanExecuteChanged
is called in the RelayCommand
class, to enable/disable the button:
public void RaiseCanExecuteChanged()
{
CanExecuteChanged(this, EventArgs.Empty);
}
the two delegates of the command are set in the constructor:
public RelayCommand(Action executeMethod, Func<bool> canExecuteMethod)
{
_TargetExecuteMethod = executeMethod;
_TargetCanExecuteMethod = canExecuteMethod;
}
but when the error state changed (when RaiseCanExecuteChanged
is called) the CanSave
method doesn't get called, after a while I changed the Command
initialization way to be set in the constructor instead:
public AddEditCustomerViewModel()
{
SaveCommand = new RelayCommand(OnSave, CanSave);
}
public RelayCommand SaveCommand {get;}
and it works! but why?