0

我有一个绑定到 WPF 数据网格的 ReactiveCollection。其中一列是复选框列。

WPF 表单有一个绑定到 ReactiveCommand 的按钮。

我要做的只是在所有复选框都被勾选的情况下启用按钮。

        var canHitContinueButton = this.WhenAny( x => x.MyCollection, ticks => ticks.Value.All(y => y.IsSelected));

        Continue = new ReactiveCommand(canHitContinueButton);

        Continue.Subscribe( doSomething => ());

似乎 ReactiveCommand 仅在实例化时检查值,而在 ReactiveCollection 中的项目更改时不会重新检查值。(ReactiveCollection 中的项目是 ReactiveObjects,所以我假设一切都应该自动触发。)

如何让按钮响应 ReactiveCollection 中对 ReactiveObjects 的更改?

4

1 回答 1

0

好的,终于搞定了。我想出了两种不同的方法,但不确定它们是否是最好的方法。

第一个使用 ReactiveCollection.Changed 事件:

CanHitToggleButton = Customers.Changed.Select( _ => Customers.All(x => x.IsSelected)).StartWith(false);

此解决方案可能代价高昂,因为每次集合更改时都会执行谓词,无论更改是否与复选框相关。

仅当复选框值更改时才会触发其他解决方案。

CanHitToggleButton = Customers.ItemChanged.Where(x => x.PropertyName == "IsSelected").Select(_ => Customers.All(x => x.IsSelected)).StartWith(false);
于 2012-03-01T08:47:50.793 回答