summaryrefslogtreecommitdiff
path: root/Juick/Classes/DelegateCommand.cs
blob: 40256e58a123104c3d46412eb93aa91385f8e5ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Windows.Input;

namespace Juick.Classes
{
    public class DelegateCommand : ICommand
    {
        readonly Action<object> action;
        readonly Func<bool> canExecute;

        public DelegateCommand(Action<object> 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(parameter);
        }

        public void NotifyCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, EventArgs.Empty);
            }
        }
    }
}