小编Lap*_*ish的帖子

如何订阅 SourceList.Count 并将其转换为 IObservable?

我创建 ValidatableModelBase 类并遇到一些麻烦。我需要订阅 SourceCache 更改并将 Count 集合转换为 IObservable bool 。我该怎么做?

private readonly SourceCache<ValidationResult, string> _results;

public IObservalbe<bool> IsValid { get; }

public ValidatableModelBase()
{
    _results = new SourceCach<ValidationResult, string>(x => x.PropertyName);

    //Doesn't work. I think because i dont .Subscribe() to changes?
    IsValid = _results.Connect().IsEmpty();
}
Run Code Online (Sandbox Code Playgroud)

更新:

HasErrors = collection.CountChanged.Subscribe(x => {Count = x;});
IsValid = this.WhenAnyValie(x => x.HasErrors).Select(x => x == 0);
Run Code Online (Sandbox Code Playgroud)

c# dynamic-data system.reactive reactiveui

1
推荐指数
1
解决办法
871
查看次数

标签 统计

c# ×1

dynamic-data ×1

reactiveui ×1

system.reactive ×1