【发布时间】:2017-04-01 13:58:59
【问题描述】:
我正在使用 ReactiveCommand 并将其绑定到一个按钮,并让该按钮在命令执行时自动禁用,效果很好。
现在我有 2 个 ReactiveCommand 和 2 个按钮,我希望在执行任何命令时禁用 2 个按钮。我尝试的是:
public class MyClass
{
public MyClass()
{
ReadClFilesCommand = ReactiveCommand.Create(ReadClFiles, c.IsExecuting.Select(exe => !exe));
WriteClFilesCommand = ReactiveCommand.Create(WriteClFiles, ReadClFilesCommand.IsExecuting.Select(exe => !exe));
}
}
它看起来非常优雅,我喜欢它的干净。但是当我尝试运行代码时,我得到了 NullReferenceException 的 WriteClFilesCommand,因为它还没有创建。
我想我需要先创建命令,然后再设置它的 CanExecute,但 CanExecute 是只读的。
也许我可以创建一个单独的 IObserable 并让 ReadClFilesCommand.CanExecute 和 WriteClFilesCommand.CanExecute 进入,可以吗?
还有其他方法吗?
谢谢。
【问题讨论】:
标签: wpf reactiveui