/
n-dimens
/
pascalabcnet
Обзор
Документация
Войти
/
n-dimens
/
pascalabcnet
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
VisualPascalABCNET/FormsDesignerBinding/Dependecies/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/RelayCommand.cs
158 строк
4 KB
Бондарев Иван
initial commit
14 май 2015, 22:35
14 май 2015, 22:35
e6e67c1
Код
Авторство
О чём код?
/* * Created by SharpDevelop. * User: Peter Forstmeier * Date: 16.10.2011 * Time: 19:40 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Diagnostics; using System.Windows.Input; namespace ICSharpCode.SharpDevelop.Widgets { /// <summary> /// Description of RelayCommand. /// </summary> public class RelayCommand<T> : System.Windows.Input.ICommand { #region Declarations readonly Predicate<T> _canExecute; readonly Action<T> _execute; #endregion #region Constructors /// <summary> /// Initializes a new instance of the <see cref="RelayCommand<T>"/> class and the command can always be executed. /// </summary> /// <param name="execute">The execution logic.</param> public RelayCommand(Action<T> execute) : this(execute, null) { } /// <summary> /// Initializes a new instance of the <see cref="RelayCommand<T>"/> class. /// </summary> /// <param name="execute">The execution logic.</param> /// <param name="canExecute">The execution status logic.</param> public RelayCommand(Action<T> execute, Predicate<T> canExecute) { if (execute == null) throw new ArgumentNullException("execute"); _execute = execute; _canExecute = canExecute; } #endregion #region ICommand Members public event EventHandler CanExecuteChanged { add { if (_canExecute != null) CommandManager.RequerySuggested += value; } remove { if (_canExecute != null) CommandManager.RequerySuggested -= value; } } [DebuggerStepThrough] public Boolean CanExecute(Object parameter) { return _canExecute == null ? true : _canExecute((T)parameter); } public void Execute(Object parameter) { _execute((T)parameter); } #endregion } /// <summary> /// A command whose sole purpose is to relay its functionality to other objects by invoking delegates. The default return value for the CanExecute method is 'true'. /// </summary> public class RelayCommand : System.Windows.Input.ICommand { #region Declarations readonly Func<Boolean> _canExecute; readonly Action _execute; #endregion #region Constructors /// <summary> /// Initializes a new instance of the <see cref="RelayCommand<T>"/> class and the command can always be executed. /// </summary> /// <param name="execute">The execution logic.</param> public RelayCommand(Action execute) : this(execute, null) { } /// <summary> /// Initializes a new instance of the <see cref="RelayCommand<T>"/> class. /// </summary> /// <param name="execute">The execution logic.</param> /// <param name="canExecute">The execution status logic.</param> public RelayCommand(Action execute, Func<Boolean> canExecute) { if (execute == null) throw new ArgumentNullException("execute"); _execute = execute; _canExecute = canExecute; } #endregion #region ICommand Members public event EventHandler CanExecuteChanged { add { if (_canExecute != null) CommandManager.RequerySuggested += value; } remove { if (_canExecute != null) CommandManager.RequerySuggested -= value; } } [DebuggerStepThrough] public Boolean CanExecute(Object parameter) { return _canExecute == null ? true : _canExecute(); } public void Execute(Object parameter) { _execute(); } #endregion } }