ReactiveUI - ViewCell 绑定

ReactiveUI - ViewCell Binding

我正在尝试重现 ReactiveUI 的 101 example 并使其适应 Xamarin Forms

我使用自定义 ViewCell 但无法以 ReactiveUI 方式绑定它:

public partial class FlickrPhotoCell : ViewCell, IViewFor<FlickrPhotoModel>
{
    public FlickrPhotoCell()
    {
        InitializeComponent();
        this.Bind(ViewModel, vm => vm.Title, v => v.TitleLabel.Text);
        this.Bind(ViewModel, vm => vm.Description, v => v.DescriptionLabel.Text);
        this.Bind(ViewModel, vm => vm.Url, v => v.UrlImage.Source, null, new CustomConverter());
    }

    //The rest of the code below is plumbing:

    public static readonly BindableProperty ViewModelProperty = BindableProperty.Create(nameof(ViewModel), typeof(FlickrPhotoModel), typeof(FlickrPhotoCell));

    public FlickrPhotoModel ViewModel
    {
        get { return (FlickrPhotoModel)GetValue(ViewModelProperty); }
        set { SetValue(ViewModelProperty, value); }
    }

    object IViewFor.ViewModel
    {
        get { return ViewModel; }
        set { ViewModel = (FlickrPhotoModel)value; }
    }
}

而如果我按照通常的 Xamarin Forms 方式进行操作则效果很好:

public FlickrPhotoCell()
    {
        InitializeComponent();
        TitleLabel.SetBinding<FlickrPhotoModel>(Label.TextProperty, x => x.Title);
        DescriptionLabel.SetBinding<FlickrPhotoModel>(Label.TextProperty, x => x.Description);
        UrlImage.SetBinding<FlickrPhotoModel>(Image.SourceProperty, x => x.Url);
    }

我认为一个区别是 Xamarin Forms 方式使用 BindingContext 而 ReactiveUI 方式纯粹使用 ViewModel。所以我的第一个猜测是 ViewModel 属性 没有设置。也许尝试将 BindingContext 绑定到 ViewModel?或者覆盖 OnBindingContext Changed 并在那里设置 ViewModel 以查看是否有效