1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- namespace EfemDualUI.Controls.Common
- {
- public class RelayCommand : ICommand
- {
- private readonly Func<Object, Boolean> canExecute;
- private readonly Action<Object> execute;
- public RelayCommand(Action<Object> execute) : this(execute, null)
- {
- }
- public RelayCommand(Action<Object> execute, Func<Object, Boolean> canExecute)
- {
- this.execute = execute ?? throw new ArgumentNullException("execute");
- this.canExecute = canExecute;
- }
- public event EventHandler CanExecuteChanged
- {
- add
- {
- if (canExecute != null)
- CommandManager.RequerySuggested += value;
- }
- remove
- {
- if (canExecute != null)
- CommandManager.RequerySuggested -= value;
- }
- }
- public Boolean CanExecute(Object parameter)
- {
- return canExecute == null ? true : canExecute(parameter);
- }
- public void Execute(Object parameter)
- {
- execute(parameter);
- }
- }
- }
|