Moving from RelayCommand to ReactiveCommand

548 Views Asked by At

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;
}
1

There are 1 best solutions below

4
On BEST ANSWER

How about this:

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

GodkendeBilagCommand = ReactiveCommand.Create(canExecute);