using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace BPASmartClient.SCADAControl.Converters { public class RelayCommandSimple :ICommand, IDisposable { private Action _executeCallback; private Func _canExecute; public RelayCommandSimple(Action execute) { _executeCallback = execute; } public RelayCommandSimple(Action execute,Func canExecute) : this(execute) { _canExecute = canExecute; } public bool CanExecute(object parameter) { if (_canExecute == null) return true; return _canExecute(); } public void Execute(object parameter) { _executeCallback(); } public void Dispose() { _executeCallback = null; _canExecute = null; } public event EventHandler CanExecuteChanged { add { if (this._canExecute != null) { CommandManager.RequerySuggested += value; } } remove { if (this._canExecute != null) { CommandManager.RequerySuggested -= value; } } } } public class RelayCommandSimple :ICommand { private Action _executeCallback; private Func _canExecute; public RelayCommandSimple(Action execute) { if (execute == null) throw new ArgumentNullException("execute"); _executeCallback = execute; } public RelayCommandSimple(Action execute,Func canExecute) : this(execute) { _canExecute = canExecute; } public bool CanExecute(object parameter) { if (_canExecute == null) return true; if (parameter != null && parameter is TParam) { return _canExecute((TParam)parameter); } return true; } public void Execute(object parameter) { if (parameter != null && parameter is TParam) { _executeCallback((TParam)parameter); } } public event EventHandler CanExecuteChanged { add { if (this._canExecute != null) { CommandManager.RequerySuggested += value; } } remove { if (this._canExecute != null) { CommandManager.RequerySuggested -= value; } } } } public class RelayCommandSimpleNull :ICommand { private Action _executeCallback; private Func _canExecute; public RelayCommandSimpleNull(Action execute) { if (execute == null) throw new ArgumentNullException("execute"); _executeCallback = execute; } public RelayCommandSimpleNull(Action execute,Func canExecute) : this(execute) { _canExecute = canExecute; } public bool CanExecute(object parameter) { if (_canExecute == null) return true; return _canExecute((T)parameter); } public void Execute(object parameter) { _executeCallback((T)parameter); } public event EventHandler CanExecuteChanged { add { if (this._canExecute != null) { CommandManager.RequerySuggested += value; } } remove { if (this._canExecute != null) { CommandManager.RequerySuggested -= value; } } } } }