如果 CleanCommand 正在执行,则 SearchCommand 将处于非活动状态。如果 SearchCommand 正在执行,则 CleanCommand 将处于非活动状态。
条码是
public long Barcode
{
get => _barcode;
set => this.RaiseAndSetIfChanged(ref _barcode, value);
}
private readonly ObservableAsPropertyHelper<bool> _isSearching;
private readonly ObservableAsPropertyHelper<bool> _isCleaning;
public bool IsSearching => _isSearching.Value;
public bool IsCleaning => _isCleaning.Value;
public ReactiveCommand<Unit, Unit> SearchCommand { get; }
public ReactiveCommand<Unit, Unit> CleanCommand { get; }
在构造函数中
SearchCommand = ReactiveCommand.CreateFromObservable(Search, SearchCanExecute());
SearchCommand.IsExecuting.ToProperty(this, x => x.IsSearching, out _isSearching);
CleanCommand = ReactiveCommand.CreateFromObservable(Clean, CleanCanExecute());
CleanCommand.IsExecuting.ToProperty(this, x => x.IsCleaning, out _isCleaning);
在班上
IObservable<bool> SearchCanExecute()
{
bool isCleaningSuited = !IsCleaning;
bool isBarcodeSuited = Barcode > 0;
return Observable.Return(isBarcodeSuited);
}
IObservable<bool> CleanCanExecute()
{
bool isSearchingSuited = !IsSearching;
return Observable.Return(isSearchingSuited);
}
我通过 *IsExecuting.ToProperty() 获得进程状态
我得到带有条形码等属性的值。
我应该使用WhenAny* 方法还是可以这样做?