ReactiveList and WhenAny

左心房为你撑大大i 提交于 2019-12-05 01:14:48

问题


I have a number of check lists held in ReactiveLists that have ChangeTrackingEnabled = true. I want to only enable my OkCommand when there is at least one item checked in each list.

In addition there are various other properties that I want to ensure are filled in with a valid byte value.

I've tried doing the following but it doesn't work:

        this.OkCommand = new ReactiveCommand(this.WhenAny(
            x => x.Property1,
            x => x.Property1,
            x => x.Property1,
            x => x.List1,
            x => x.List2,
            x => x.List3,
            (p1, p2, p3, l1, l2, l3) =>
            {
                byte tmp;
                return byte.TryParse(p1.Value, out tmp) &&
                       byte.TryParse(p2.Value, out tmp) &&
                       byte.TryParse(p3.Value, out tmp) &&
                       l1.Value.Any(x => x.IsChecked) &&
                       l2.Value.Any(x => x.IsChecked) &&
                       l3.Value.Any(x => x.IsChecked);
            }));

It seems the property change notifications aren't being propagated to WhenAny. Any idea what I should be doing?


回答1:


This is testing when someone sets the list itself, i.e. when:

this.List1 = new ReactiveList<Foo>();

Instead, you want something like:

this.WhenAnyObservable(x => x.List1.ItemChanged, x => x.List2.ItemChanged)
    .Where(x => x.PropertyName == "IsChecked")
    .Select(_ => List1.Any(x => x.IsChecked) && List2.Any(x => x.IsChecked));


来源:https://stackoverflow.com/questions/20225705/reactivelist-and-whenany

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!