ICommand
インターフェイスはメソッドも定義しますCanExecute
。false
実行が開始されたときにそのコマンドを返し、true
完了時に戻すことができます。これにより、コマンドの実行中にボタンを無効にするという利点も得られます。
私はを扱っていないので、のメソッドRelayCommand
と同等のものがあるかどうかはわかりませんが、 (これは基本的に と同じことを行います) を使用すると、次のようなことができます (この実装はスレッドではないことに注意してください)。安全):DelegateCommand
RaiseCanExecuteChanged
DelegateCommand
RelayCommand
SaveCommand = new DelegateCommand<CommandParam>(MyCommandExecute, MyCommandCanExecute);
private bool canExecute;
private bool MyCommandCanExecute()
{
return canExecute;
}
private void MyCommandExecute(CommandParam parm)
{
// Change the "can execute" status and inform the UI.
canExecute = false;
SaveCommand.RaiseCanExecuteChanged();
DoStuff();
// Change the "can execute" status and inform the UI.
canExecute = true;
SaveCommand.RaiseCanExecuteChanged();
}