2017-02-01 7 views
2

私はReactiveUIの101 exampleを再現し、それをXamarin Formsに適応しようとしています。ReactiveUI - ViewCell Binding

私はカスタムViewCellを使用しますが、ReactiveUI方法、それをバインドすることはできません:私はそれをいつもXamarin Forms道をすれば、それは正常に動作に対し

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

:私は思う

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

View Xaml、特にListViewを追加できますか? – Giusepe

+0

私は、Xamarin Formsの方法はBindingContextを使用していますが、ReactiveUIの方法はViewModelだけを使用している点です。だから私の最初の推測は、ViewModelプロパティが設定されていないことです。おそらく、BindingContextをViewModelにバインドしようとしますか?または、OnBindingContextをオーバーライドするViewModelを変更して、それが動作するかどうかを確認してください。 –

+0

これは分かりやすいコメントのようです。私は今しよう! –

答えて

1

1つの違いはということですXamarin Formsの方法はBindingContextを使用していますが、ReactiveUIの方法はViewModelのみを使用しています。だから私の最初の推測は、ViewModelプロパティが設定されていないことです。おそらく、BindingContextをViewModelにバインドしようとしますか?またはOnBindingContextをオーバーライドするViewModelを変更して、それが正常に機能するかどうかを確認してください。