カスタムセルにバインドする作業リストビューがあります。しかし、実際にカスタムセルのプロパティと同じ名前のプロパティを持つモデルを実際に持っている必要があるのだろうかと思います。Xamarinハードコードされたプロパティ名を持たないカスタムセルへのフォームのバインド
マイカスタムviewcell(ものがたくさん出て左):
public class RecordListCell : ViewCell
{
public static readonly BindableProperty HeadingProperty = BindableProperty.Create ("Heading", typeof (string), typeof (RecordListCell), null);
public string Heading {
get { return (string)GetValue (HeadingProperty); }
set { SetValue (HeadingProperty, value); }
}
protected Label headingLbl { get; set; }
public RecordListCell()
{
headingLbl = new Label() ;
headingLbl.SetBinding (Label.TextProperty, new Binding ("Heading"));
// from here on I construct a stacklayout and insert the label above
}
}
マイページ(ものがたくさん出て左)
public TopicsPage()
{
_topicList = new ListView();
var cell = new DataTemplate (typeof (RecordListCell));
// NOT WORKING
// cell.SetBinding (RecordListCell.HeadingProperty, "Name");
// working (I must name the property exactly like the property in my custom cell)
cell.SetBinding (RecordListCell.HeadingProperty, "Heading");
_topicList.ItemTemplate = cell;
_topicList.ItemsSource = MyRepo.GetTopics();
}
したがって、上記の作品が、私はMyRepoを持っていることを強制しています.GetTopics()は、Headingという名前のプロパティを持つオブジェクトのリストを返します。私はこのカスタムセルをあらゆる種類のオブジェクトリストで再利用したいと思いますし、私のコメントのようにページ上のバインディングを指定するだけですが、これはうまくいきません。
ここで間違ったことが予想されるのですか、私のアプローチが間違っていますか?
あなたは、見出しの同じページに対する一定になるように期待していますか?または見出しのコンテンツがアイテムのコンテンツによって動的になることを期待していますか? – Frankie
同じページの定数ですが、多くのページで同じカスタムセルを使用したいので、セルにモデルプロパティの名前を付ける必要はありません –