我是WPF的新手,使用reactiveUI实现应用程序。我有一个按钮并为它添加了命令处理程序。只在canExecute为真时才调用该方法。
在视图模型中,我已经定义了它。
public bool canExecute
{
get { return _canExecute;}
set { _canExecute = value;}
}
Bind()
{
AddRecord = new ReactiveCommand(_canExecute);
AddRecord .Subscribe(x =>
{
AddR()
}
}
void AddR()
{
}但这不管用。如何将其转换为System.IObservable?
发布于 2014-06-02 21:31:05
正如@jomtois所提到的,您需要修复CanExecute声明:
bool canExecute;
public bool CanExecute {
get { return canExecute; }
set { this.RaiseAndSetIfChanged(ref canExecute, value); }
}然后,你可以写:
AddRecord = new ReactiveCommand(this.WhenAnyValue(x => x.CanExecute));为什么要这么努力呢?这使得当CanExecute更改时,ReactiveCommand会自动启用/禁用。但是,这个设计是非常必要的,我不会创建CanExecute布尔值,我会考虑如何组合与ViewModel相关的具有语义意义的属性。
https://stackoverflow.com/questions/23991420
复制相似问题