|
- 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<bool> _canExecute;
-
- public RelayCommandSimple(Action execute)
- {
- _executeCallback = execute;
- }
-
- public RelayCommandSimple(Action execute,Func<bool> 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<TParam> :ICommand
- {
- private Action<TParam> _executeCallback;
- private Func<TParam,bool> _canExecute;
-
- public RelayCommandSimple(Action<TParam> execute)
- {
- if (execute == null)
- throw new ArgumentNullException("execute");
-
- _executeCallback = execute;
- }
-
- public RelayCommandSimple(Action<TParam> execute,Func<TParam,bool> 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<T> :ICommand
- {
- private Action<T> _executeCallback;
- private Func<T,bool> _canExecute;
-
- public RelayCommandSimpleNull(Action<T> execute)
- {
- if (execute == null)
- throw new ArgumentNullException("execute");
-
- _executeCallback = execute;
- }
-
- public RelayCommandSimpleNull(Action<T> execute,Func<T,bool> 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;
- }
- }
- }
- }
- }
|