ReactiveCommand not respecting canExecute

穿精又带淫゛_ 提交于 2019-12-24 03:13:48

问题


Perhaps I'm missing something, however I can't get ReactiveCommand to prevent execution based on the canExecute observable.

Below is the simplest example I can conjure. I would expect the command to never fire, however it is.

What am I missing?

void Main()
{
    var canExecute = Observable.Return(false);
    var myCommand = ReactiveCommand.CreateAsyncTask(canExecute, m => functions.doAllThings(m));

    myCommand.Subscribe(x=>"executing".Dump());

    myCommand.Execute("Tom"); // This fires the command. I would have expected it to block
}

static class functions
{
    public static Task doAllThings(object message)
    {
        var result = Task.Run(() =>{
                    "running task...".Dump();
                    return "hello " + (string)message;});

        return result;
    }
}

Note - This is question is kind of a 'fork' from Executing a command from another command. I believe that this is more the core issue.


回答1:


This is by-design. ReactiveUI doesn't stop you from explicitly calling Execute / ExecuteAsync, and trusts that You Know What You're Doing™



来源:https://stackoverflow.com/questions/25636199/reactivecommand-not-respecting-canexecute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!