Created
April 17, 2013 23:14
-
-
Save thomaslevesque/5408535 to your computer and use it in GitHub Desktop.
Basic DelegateCommand implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Input; | |
namespace QuestionableContent.Input | |
{ | |
public class DelegateCommand : ICommand | |
{ | |
private readonly Action _execute; | |
private readonly Func<bool> _canExecute; | |
public DelegateCommand(Action execute, Func<bool> canExecute = null) | |
{ | |
_execute = execute; | |
_canExecute = canExecute; | |
} | |
public bool CanExecute(object parameter) | |
{ | |
return _canExecute == null || _canExecute(); | |
} | |
public void Execute(object parameter) | |
{ | |
_execute(); | |
} | |
public event EventHandler CanExecuteChanged; | |
public void RaiseCanExecuteChanged() | |
{ | |
var handler = CanExecuteChanged; | |
if (handler != null) | |
handler(this, EventArgs.Empty); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment