Skip to content

Instantly share code, notes, and snippets.

@boronology
Created February 17, 2019 00:54
Show Gist options
  • Save boronology/c181fd19b5bd12e8b05e6a6a3f70b757 to your computer and use it in GitHub Desktop.
Save boronology/c181fd19b5bd12e8b05e6a6a3f70b757 to your computer and use it in GitHub Desktop.
WPFの定番コード集その1。Command
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