Skip to content

Instantly share code, notes, and snippets.

@Vaccano
Created January 10, 2011 19:33
Show Gist options
  • Save Vaccano/773312 to your computer and use it in GitHub Desktop.
Save Vaccano/773312 to your computer and use it in GitHub Desktop.
SimpleCommand.cs
public class SimpleCommand<T> : ICommand
{
public Predicate<T> CanExecuteDelegate { get; set; }
public Action<T> ExecuteDelegate { get; set; }
#region ICommand Members
public bool CanExecute(object parameter)
{
if (CanExecuteDelegate != null)
return CanExecuteDelegate((T)parameter);
return true;// if there is no can execute default to true
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
if (ExecuteDelegate != null)
ExecuteDelegate((T)parameter);
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment