6

ユーザー確認で非同期削除操作を実行する必要があります。このようなもの:

public ReactiveAsyncCommand DeleteCommand { get; protected set; }
...
DeleteCommand = new ReactiveAsyncCommand();
DeleteCommand.RegisterAsyncAction(DeleteEntity);

...

private void DeleteEntity(object obj)
{
    if (MessageBox.Show("Do you really want to delete this entity?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
    {
        //some delete operations
    }
}

問題は、MessageBox も非同期で実行されることです。ReactiveUI でユーザーに同期的に質問し、メソッドを非同期的に実行するのに最適なパターンはどれですか?

4

1 に答える 1

6

これを行う最も簡単な方法は、次の 2 つのコマンドを使用することです。

public ReactiveCommand DeleteCommand { get; protected set; }
private ReactiveAsyncCommand ExecuteDelete { get; protected set; }

/*
 * In the Constructor
 */

ExecuteDelete = new ReactiveAsyncCommand();
ExecuteDelete.RegisterAsyncAction(() => /* Do the delete */);

DeleteCommand = new ReactiveCommand(ExecuteDelete.CanExecuteObservable);
DeleteCommand
    .Where(_ => MessageBox.Show("Delete?") == MessageBoxResult.Yes)
    .InvokeCommand(ExecuteDelete);
于 2012-09-07T05:42:15.710 に答える