diff options
Diffstat (limited to 'Juick/Classes/DelegateCommand.cs')
-rw-r--r-- | Juick/Classes/DelegateCommand.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Juick/Classes/DelegateCommand.cs b/Juick/Classes/DelegateCommand.cs new file mode 100644 index 0000000..cc7adcd --- /dev/null +++ b/Juick/Classes/DelegateCommand.cs @@ -0,0 +1,37 @@ +using System; +using System.Windows.Input; + +namespace Juick.Classes +{ + public class DelegateCommand : ICommand + { + readonly Action action; + readonly Func<bool> canExecute; + + public DelegateCommand(Action execute, Func<bool> canExecute) + { + this.action = execute; + this.canExecute = canExecute; + } + + public bool CanExecute(object parameter) + { + return canExecute(); + } + + public event EventHandler CanExecuteChanged; + + public void Execute(object parameter) + { + action(); + } + + public void NotifyCanExecuteChanged() + { + if (CanExecuteChanged != null) + { + CanExecuteChanged(this, EventArgs.Empty); + } + } + } +} |