| 123456789101112131415161718192021222324252627282930313233 |
- using System;
- using System.Windows.Input;
- namespace ComputerShopWpf.Helpers
- {
- public class RelayCommand : ICommand
- {
- private readonly Action<object> _execute;
- private readonly Predicate<object> _canExecute;
- public RelayCommand(Action<object> execute, Predicate<object> canExecute = null)
- {
- _execute = execute;
- _canExecute = canExecute;
- }
- public bool CanExecute(object parameter)
- {
- return _canExecute == null || _canExecute(parameter);
- }
- public void Execute(object parameter)
- {
- _execute(parameter);
- }
- public event EventHandler CanExecuteChanged
- {
- add { CommandManager.RequerySuggested += value; }
- remove { CommandManager.RequerySuggested -= value; }
- }
- }
- }
|