Created
March 31, 2022 11:23
-
-
Save Tocchann/d4a28480ec97d2af65d03388607938db to your computer and use it in GitHub Desktop.
ICommand のミニマムベースクラス
This file contains hidden or 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.Diagnostics; | |
using System.Windows.Input; | |
namespace SimpleMVVM | |
{ | |
public class RelayCommand : ICommand | |
{ | |
private readonly Action<object> execute; | |
private readonly Predicate<object> canExecute; | |
public RelayCommand( Action<object> execute_ ) | |
: this( execute_, null ) | |
{ | |
} | |
public RelayCommand( Action<object> execute_, Predicate<object> canExecute_ ) | |
{ | |
execute = execute_; | |
canExecute = canExecute_; | |
} | |
public event EventHandler CanExecuteChanged | |
{ | |
add { CommandManager.RequerySuggested += value; } | |
remove { CommandManager.RequerySuggested -= value; } | |
} | |
[DebuggerStepThrough] | |
public bool CanExecute( object parameter ) | |
{ | |
return canExecute == null ? true : canExecute( parameter ); | |
} | |
public void Execute( object parameter ) | |
{ | |
execute( parameter ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment