| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System;
- using System.Windows.Input;
- namespace SAGA.DotNetUtils.WPF
- {
- public class BaseCommand : ICommand
- {
- private Func<object, bool> m_canExecute;
- private Action<object> m_execute;
- public event EventHandler CanExecuteChanged
- {
- add
- {
- System.Windows.Input.CommandManager.RequerySuggested += value;
- }
- remove
- {
- System.Windows.Input.CommandManager.RequerySuggested -= value;
- }
- }
- public BaseCommand(Action<object> execute, Func<object, bool> canExecute)
- {
- this.m_execute = execute;
- this.m_canExecute = canExecute;
- }
- public virtual bool CanExecute(object parameter)
- {
- if (this.m_canExecute != null)
- {
- return this.m_canExecute.Invoke(parameter);
- }
- return true;
- }
- public virtual void Execute(object parameter)
- {
- if (this.m_execute != null)
- {
- this.m_execute(parameter);
- }
- }
- }
- }
|