gpt4 book ai didi

c# - 具有多个 ReactiveCommand IsExecuting 的单个 ObservableAsPropertyHelper

转载 作者:行者123 更新时间:2023-11-30 16:52:25 24 4
gpt4 key购买 nike

来自样本here ,我正在尝试将 _SpinnerVisibility 更改为多个 reactivecommand 对象。所以下面的片段显示了我所做的..

public ReactiveCommand<object> ExecuteSearch { get; protected set; }

public ReactiveCommand<List<string>> OtherOperation { get; protected set; }

public AppViewModel(ReactiveCommand<object> testExecuteSearchCommand = null, IObservable<List<FlickrPhoto>> testSearchResults = null)
{

_SpinnerVisibility = OtherOperation.IsExecuting.Select(x=> x? Visibility.Visible : Visibility.Collapsed)
.ToProperty(this, x => x.SpinnerVisibility, Visibility.Hidden);
_SpinnerVisibility = ExecuteSearch.IsExecuting.Select(x=> x? Visibility.Visible : Visibility.Collapsed)
.ToProperty(this, x => x.SpinnerVisibility, Visibility.Hidden);
}

我在这里根据多个 react 命令设置可见性。但总是最后注册的命令会触发可见性。有没有办法根据 react 命令 ExecuteSearch, OtherOperation 更改可见性?

最佳答案

您需要将两个 IsExecuting 可观察对象合并为一个。

如果您的命令是互斥的(即它们不能同时执行),这应该可行:

_SpinnerVisibility = new IReactiveCommand[] { ExecuteSearch, OtherOperation }
.Select(cmd => cmd.IsExecuting)
.Merge()
.Select(x=> x? Visibility.Visible : Visibility.Collapsed)
.ToProperty(this, x => x.SpinnerVisibility, Visibility.Hidden);

如果可以,那么它会更像:

_SpinnerVisibility = new IReactiveCommand[] { ExecuteSearch, OtherOperation }
.Select(cmd => cmd.IsExecuting)
.CombineLatest()
.Select(x => x.Any() ? Visibility.Collapsed : Visibility.Visible)
.ToProperty(this, x => x.SpinnerVisibility, Visibility.Hidden);

两者都适用于任意数量的命令。

关于c# - 具有多个 ReactiveCommand IsExecuting 的单个 ObservableAsPropertyHelper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32588585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com