如何使用 Xamarin Forms 在 ReactiveUI 7 中创建接收字符串的 ReactiveCommand

How to create a ReactiveCommand that receives a string in ReactiveUI 7 with Xamarin Forms

在我的 LoginPage.xaml.cs 我有一个 webview wview。当我的 wview 触发 Navigated 事件时,我想在我的 ViewModel 中执行命令。我的命令应该从我的网络视图中收到 url。

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);
}

如何创建可以对此做出反应的命令?以下代码无法编译(委托操作不接受 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();
        }); 
}

明确说明 Action 的类型参数,它将编译:

public LoginViewModel(IScreen hostScreen = null) : base(hostScreen)
{
    VerifyCallbackUrl = ReactiveCommand.Create(new Action<string>(xUrl => { DoSomethingUseful(); }));
}