using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace MVVMDatabaseSample.ViewModel { internal class DelegateCommand : ICommand { private readonly Func _canExecute; private readonly Action _execute; public event EventHandler? CanExecuteChanged; public DelegateCommand(Action execute, Func canExecute) { _execute = execute; _canExecute = canExecute; } public DelegateCommand(Action execute) : this(execute, null) { } public bool CanExecute(object? parameter) { if (_canExecute == null) return true; return _canExecute(); } public void Execute(object? parameter) { _execute(); } public void RaiseCanExecuteChanged() { if (this.CanExecuteChanged != null) this.CanExecuteChanged(this, EventArgs.Empty); } } }