Question

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?

Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top