我需要通过用户确认执行异步删除操作。像这样的东西:

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中最好的模式是同步询问用户然后异步执行方法?

最佳答案

最简单的方法是只使用两个命令:

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);

10-06 11:24