Created
February 17, 2019 00:54
-
-
Save boronology/c181fd19b5bd12e8b05e6a6a3f70b757 to your computer and use it in GitHub Desktop.
WPFの定番コード集その1。Command
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.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Input; | |
namespace TemplateApp.ViewModel | |
{ | |
public class Command : ICommand | |
{ | |
public event EventHandler CanExecuteChanged; | |
private bool isExecutable; | |
public bool IsExecutable | |
{ | |
get { return isExecutable; } | |
set { isExecutable = value; CanExecuteChanged?.Invoke(this, new EventArgs()); } | |
} | |
private Action<object> commandAction; | |
public bool CanExecute(object parameter) | |
{ | |
return IsExecutable; | |
} | |
public void Execute(object parameter) | |
{ | |
this.commandAction?.Invoke(parameter); | |
} | |
public Command(Action<object> action) | |
{ | |
commandAction = action; | |
IsExecutable = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment