本文共 1065 字,大约阅读时间需要 3 分钟。
public class RelayCommand : ICommand { private Action _execute; private Predicate _canExecute; public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public RelayCommand(Action execute) : this(execute, null) { } public RelayCommand(Action execute, Predicate canExecute) { if (execute == null) { throw new ArgumentNullException("execute"); } this._execute = execute; this._canExecute = canExecute; } [DebuggerStepThrough] public bool CanExecute(object parameter) { return this._canExecute == null || this._canExecute(parameter); } public void Execute(object parameter) { this._execute(parameter); } }
转载于:https://www.cnblogs.com/z-huan/p/7541515.html