【发布时间】:2016-11-24 03:22:42
【问题描述】:
我正试图围绕reactiveUI,它最近从6.5.2 更新到7.0,并且似乎包括一些关于ReactiveCommand 的重大更改。
EG 这曾经有效:
在 ViewModel 中:
public ReactiveCommand<Unit> DoLogin;
...
DoLogin = ReactiveCommand.CreateAsyncTask(
async x => {
IsBusy = true;
await Task.Delay(2500);
IsBusy = false;
return Unit.Default;
});
在视图中:
//bind the command
Observable.FromEventPattern(x => loginButton.Clicked += x, x => loginButton.Clicked -= x)
.Subscribe(args => ViewModel.DoLogin.Execute(null));
//do something after the dologin is complete
this.WhenAnyObservable(x => x.ViewModel.DoLogin)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe( x => {
DisplayAlert("login complete", "welcome", "OK");
}
);
但现在在 reactui 7.0 中,情况有所不同,我不得不进行一些更改,但我无法使其正常工作:
在 ViewModel 中:
public ReactiveCommand<Unit, Unit> DoLogin;
...
DoLogin = ReactiveCommand.CreateFromTask(
async x => {
IsBusy = true;
await Task.Delay(2500);
IsBusy = false;
return Unit.Default;
});
在视图中:
//bind the command
Observable.FromEventPattern(x => loginButton.Clicked += x, x => loginButton.Clicked -= x)
.Subscribe(args => ViewModel.DoLogin.Execute());
//do something after the dologin is complete
this.WhenAnyObservable(x => x.ViewModel.DoLogin)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe( x => {
DisplayAlert("login complete", "welcome", "OK");
}
);
命令代码仍会被执行,但 WhenANyObservable Subscribe 部分永远不会触发。它从不显示我的 DisplayAlert。
我正在使用 Xamarin 表单,如果这很重要,但即使在 Windows 表单中我也会得到相同的行为。
【问题讨论】:
标签: xamarin.forms system.reactive reactiveui