在我的LoginPage.xaml.cs中,我有一个webview wview。我想在我的wview中触发Navigated事件时在我的ViewModel中执行命令。我的命令应该从我的网页视图中收到网址。
LoginPage.xaml.cs:
protected override void OnAppearing()
{
base.OnAppearing();
Observable.FromEventPattern<WebNavigatedEventArgs>(
ev => wview.Navigated += ev,
ev => wview.Navigated -= ev)
.Select(x => x.EventArgs.Source.ToString())
.InvokeCommand(ViewModel.VerifyCallbackUrl);
}
如何创建可以对此作出反应的命令?以下代码无法编译(Delegate操作不带1个参数):
public ReactiveCommand<string,System.Reactive.Unit> VerifyCallbackUrl { get; protected set; }
public LoginViewModel(IScreen hostScreen = null) : base(hostScreen)
{
VerifyCallbackUrl = ReactiveCommand<string, System.Reactive.Unit>
.Create(xUrl =>
{
DoSomethingUseful();
});
}
答案 0 :(得分:1)
明确关于Action的类型参数,它将编译:
public LoginViewModel(IScreen hostScreen = null) : base(hostScreen)
{
VerifyCallbackUrl = ReactiveCommand.Create(new Action<string>(xUrl => { DoSomethingUseful(); }));
}