internal class DelegateCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return CanExecuteFunc == null ? true : CanExecuteFunc(parameter);
}
public void Execute(object parameter)
{
ExecuteAction?.Invoke(parameter);
}
public Action<object> ExecuteAction { get; set; }
public Func<object, bool> CanExecuteFunc { get; set; }
public DelegateCommand(Action executeMethod)
: this(executeMethod, () => true)
{
}
public DelegateCommand(Action executeMethod, Func<bool> canExecuteMethod)
{
if (executeMethod == null || canExecuteMethod == null)
{
throw new ArgumentNullException("executeMethod");
}
this.ExecuteAction = delegate
{
executeMethod();
};
this.CanExecuteFunc = (object o) => canExecuteMethod();
}
public void Execute()
{
Execute(null);
}
public bool CanExecute()
{
return CanExecute(null);
}
}
public abstract class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}