以下行抛出一个运行时异常:ReactiveCommand.Create抛出“NotSupportedException”:“索引表达式仅支持常量。”
Accept = ReactiveCommand.Create(this.WhenAnyValue(x => x.Canexecute()));
下面的代码:
public class InstructionsViewModel : ReactiveObject
{
public InstructionsViewModel()
{
Accept = ReactiveCommand.Create(this.WhenAnyValue(x => x.CanExecute));
Accept.Subscribe(x =>
{
Debug.Write("Hello World");
});
}
public ReactiveCommand<object> Accept { get; }
bool _canExecute;
public bool CanExecute { get { return _canExecute; } set { this.RaiseAndSetIfChanged(ref _canExecute, value); } }
}
错误:
Cannot convert lambda expression to type 'IObserver' because it is not a delegate type
我也试过如下:
public InstructionsViewModel()
{
Accept = ReactiveCommand.Create(this.WhenAnyValue(x => x.Canexecute()));
Accept.Subscribe(x =>
{
Debug.Write("Hello World");
});
}
public ReactiveCommand<object> Accept { get; }
public bool Canexecute() => true;
我收到以下错误:
An exception of type 'System.NotSupportedException' occurred in ReactiveUI.dll but was not handled in user code
Additional information: Index expressions are only supported with constants.
这甚至支持在Windows Phone上10?
我试过了你的建议。但是,我收到以下错误:无法将lambda表达式转换为键入'IObserver
UWP(即Windows Phone 10)支持此功能吗? –
我不得不承认,我很困惑,根据网站,这也应该在UWP上工作。你能用新版本的代码和错误细节来编辑你的问题吗? – pmbanka