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);
}
View Xaml、特にListViewを追加できますか? – Giusepe
私は、Xamarin Formsの方法はBindingContextを使用していますが、ReactiveUIの方法はViewModelだけを使用している点です。だから私の最初の推測は、ViewModelプロパティが設定されていないことです。おそらく、BindingContextをViewModelにバインドしようとしますか?または、OnBindingContextをオーバーライドするViewModelを変更して、それが動作するかどうかを確認してください。 –
これは分かりやすいコメントのようです。私は今しよう! –