|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- 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;
- }
- }
- }
- }
- }
|