LoginSignup
0
1

More than 5 years have passed since last update.

RelayCommandクラス(MVVM Light Toolkit リファレンス)

Last updated at Posted at 2018-10-25

RelayCommand

概要

public class RelayCommandRelayCommand : System.Windows.Input.ICommand
  • ICommandインターフェイスを実装したコマンド。
  • このコマンドは、CommandParameterを使用しない。
名前空間
  • GalaSoft.MvvmLight.Command
  • GalaSoft.MvvmLight.CommandWpf(WPF バージョン4.5、つまりWindows 8以上はこちらを使うこと)

アセンブリ

  • GalaSoft.MvvmLight
  • GalaSoft.MvvmLight.Platform(GalaSoft.MvvmLight.CommandWpf名前空間)

メソッド

コンストラクター

コンストラクター
public RelayCommand(System.Action execute, bool keepTargetAlive = False)
public RelayCommand(System.Action execute, System.Func<bool> canExecute, bool keepTargetAlive = False)
概要
  • executeは、コマンドを実行するときに呼ぶメソッド。
  • canExecuteは、コマンドを実行できるかどうかを判定するメソッド。canExecuteを指定しない場合は、コマンドが常に実行できるとみなす。
  • keepTargetAliveは、executecanExecuteがクロージャーの場合、trueにすること。それ以外の場合は、メモリリークを防ぐため、falseにすること。
例外
  • System.ArgumentNullException: executenullである。

CanExecute

CanExecute
public bool CanExecute(object parameter)
概要
  • コマンドを実行できるかどうかを判定するメソッド。
  • コンストラクターでcanExecuteを指定していれば、それを呼ぶ。
  • コンストラクターでcanExecuteを指定していなければ、常にtrueを戻す。
戻り値
  • コマンドを実行できる状態ならtrue、実行できないならfalseを戻す。(そのようなcanExecuteを指定すること)

Execute

Execute
public virtual void Execute(object parameter)
概要
  • コマンドの実行そのものであるメソッド。
  • コンストラクターで指定したexecuteを呼ぶ。

RaiseCanExecuteChanged

RaiseCanExecuteChanged
public void RaiseCanExecuteChanged()
概要
  • このコマンドを実行できるかどうかが変化するときに、このメソッドを呼び出すこと。
  • CanExecuteChangedイベントを起こす。

イベント

CanExecuteChanged

CanExecuteChanged
public event System.EventHandler CanExecuteChanged
概要
  • このコマンドを実行できるかどうかが変化するときに起きるイベント。
  • RaiseCanExecuteChangedメソッドを呼ぶことで、起きる。

参照

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1