【发布时间】:2014-04-27 11:41:47
【问题描述】:
我的 ViewModel 中有几个命令,我想让每个按钮的 CanExecute 绑定到一个可观察到的忙,它被定义为当前没有任何按钮正在执行。
以下是我想出的,但显然它遇到了 NullReferenceException。
busy = Observable.CombineLatest(this.PlayCommand.IsExecuting, this.PauseCommand.IsExecuting, (play, pause) => play && pause);
this.PauseCommand = new ReactiveCommand(busy.Select(b => !b));
this.PlayCommand = new ReactiveCommand(busy.Select(b=> !b));
ReactiveCommand 上的 CanExecuteObservable 属性也是只读的,所以我需要在初始化命令之前定义一个 IObservable。
关于如何解决这个先有鸡还是先有蛋的问题有什么想法吗?观察 ViewModel(或 ViewModel 集合)忙碌状态的更好方法也将不胜感激:-)
【问题讨论】:
标签: c# mvvm system.reactive reactiveui