Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RelayCommand : ICommand
- {
- private readonly Action _execute;
- private readonly Predicate<bool> _canExecute; //изменил Predicate на Predicate<bool>
- public event EventHandler CanExecuteChanged;
- public RelayCommand(Action execute) : this(execute, null) { }
- public RelayCommand(Action execute, Predicate<bool> canExecute) //изменил Predicate на Predicate<bool>
- {
- if (execute == null)
- {
- throw new ArgumentNullException("предикат не должен быть равным нулю");
- }
- _execute = execute;
- _canExecute = canExecute;
- }
- public bool CanExecute(object parameter)
- {
- return _canExecute == null ? true : _canExecute((bool)parameter); //добавил параметр в аргументы с явным преобразованием
- }
- public void Execute(object parameter)
- {
- _execute();
- }
- public void RaiseCanExecuteChanged()
- {
- var handler = CanExecuteChanged;
- if (handler != null)
- {
- handler(this, EventArgs.Empty);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement