using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace MSSQL_MVVM_Sample.Structure { internal class DelegateCommand : ICommand { private readonly Action _execute; private readonly Func _canExecute; public event EventHandler? CanExecuteChanged; public DelegateCommand(Action execute) : this(execute, null) { } public DelegateCommand(Action execute, Func canExecute) { _execute = execute; _canExecute = canExecute; } 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) return; this.CanExecuteChanged(this, EventArgs.Empty); } } }