Search code examples
reactiveuirelaycommand

Moving from RelayCommand to ReactiveCommand


I am in the process of learning ReactiveUI and I am starting with commands

I have trouble translating the code for this RelayCommand to the equivalent ReactiveCommand

GodkendeBilagCommand = new RelayCommand<AdminUdbetalingsKvartal>(OnGodkendeBilag, GodkendeBilagCanExeute);

this is the code for GodkendeBilagCanExeute:

private bool GodkendeBilagCanExeute(AdminUdbetalingsKvartal kvartal)
{
    return kvartal != null && kvartal.KanGodkendeBilag && !IsBusy;
}

Solution

  • How about this:

    var canExecute = this.WhenAny(x => x.kvartal.KanGodkendeBilag, x => x.IsBusy,
        (bilag, busy) => bilag.Value && !busy.Value);
    
    GodkendeBilagCommand = ReactiveCommand.Create(canExecute);