Last active
March 12, 2021 01:59
-
-
Save chuongmep/b61565bb71354a113721ff2eb2ee7f12 to your computer and use it in GitHub Desktop.
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.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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/chuongmep/BindingWPF