【发布时间】:2019-07-24 23:05:41
【问题描述】:
我有一个 ObservableCollection,其中包含我想要观察的字符串。当第一个索引发生变化时,我想更新 ObservableAsPropertyHelper 布尔变量,如果该索引处的字符串不为空且不为空,则将其设置为 true。或者,将 Collection 转换为包含 bool 的第二个 ObservableCollection 的方法也可以。
这是我尝试过的:
public ObservableCollection<string> Difficulties { get; set; }
public extern bool Easy { [ObservableAsProperty] get; }
public Song()
{
this.WhenAny(x => x.Easy, x => x.GetValue()[0] != null && x.GetValue()[0}]!= "").ToPropertyEx(this, x => x.Easy);
}
我尝试了上面的代码,因为它适用于类似的示例:
[Reactive] public string Title { get; set; }
public extern bool Enabled { [ObservableAsProperty] get; }
public Song()
{
this.WhenAny(x => x.Title, x => x.GetValue() != null && x.GetValue() != "").ToPropertyEx(this, x => x.Enabled);
}
我对使用 Linq 表达式很陌生,所以解决方案可能很简单(比我尝试过的东西容易得多 -_-)
顺便说一句,我在 .net core 3.0 上使用 ReactiveUi.WPF 和 ReactiveUi.Fody。
【问题讨论】:
标签: c# list linq lambda reactiveui