Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace RelayCommandSample
- {
- using System;
- using System.Windows.Input;
- public class RelayCommand : ICommand
- {
- private readonly Action<object> execute;
- private readonly Predicate<object> canExecute;
- public RelayCommand(Action<object> execute)
- : this(execute, null)
- {
- }
- public RelayCommand(Action<object> execute, Predicate<object> canExecute)
- {
- this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
- this.canExecute = canExecute ?? (o => true);
- }
- public event EventHandler CanExecuteChanged
- {
- add => CommandManager.RequerySuggested += value;
- remove => CommandManager.RequerySuggested -= value;
- }
- public bool CanExecute(object parameter)
- {
- return this.canExecute(parameter);
- }
- public void Execute(object parameter)
- {
- this.execute(parameter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement