Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active March 12, 2021 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/b61565bb71354a113721ff2eb2ee7f12 to your computer and use it in GitHub Desktop.
Save chuongmep/b61565bb71354a113721ff2eb2ee7f12 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace WPFNotepad
{
/// <summary>
/// Basic implementation of implementing a windows input command.
/// </summary>
public class RelayCommand : ICommand
{
readonly Action _execute;
readonly Func<bool> _canExecute;
public RelayCommand(Action execute, Func<bool> canExecute)
{
if (execute == null)
throw new NullReferenceException("execute");
_execute = execute;
_canExecute = canExecute;
}
public RelayCommand(Action execute): this (execute, null)
{
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value;}
remove { CommandManager.RequerySuggested -= value;}
}
public bool CanExecute(object parameter)
{
return _canExecute == null? true: _canExecute();
}
public void Execute (object parameter)
{
_execute.Invoke();
}
}
}
@chuongmep
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment