ItemsView<TVisual>.ItemTemplate Özellik

Tanım

İçin uygulanacak öğesini alır veya ayarlar DataTemplate ItemsSource .

public Xamarin.Forms.DataTemplate ItemTemplate { get; set; }
member this.ItemTemplate : Xamarin.Forms.DataTemplate with get, set

Özellik Değeri

DataTemplate

DataTemplate ItemsView<TVisual> Veya içinnull

Açıklamalar

ItemTemplate, içindeki nesnelerin görsel görünümünü tanımlamak için kullanılır ItemsSource . Öğe şablonu aracılığıyla, otomatik olarak görselde doldurulacak ve kullanıcı nesnesindeki değişikliklere yanıt veren kullanıcı nesnelerine veri bağlamaları ayarlayabilirsiniz.

Öğe şablonu ise null , Xamarin. Forms. ıtemview'1. CreateDefault (System. Object) çağırılır ve sonuç görsel olarak kullanılır.

Bu örnekte, TextCell basit bir kullanıcı nesnesi için bir şablonu oluşturulur.

class Person
{
  public string FullName
  {
    get;
    set;
  }

  public string Address
  {
    get;
    set;
  }
}

void SetupView()
{
  var template = new DataTemplate (typeof (TextCell));

  // We can set data bindings to our supplied objects.
  template.SetBinding (TextCell.TextProperty, "FullName");
  template.SetBinding (TextCell.DetailProperty, "Address");

  // We can also set values that will apply to each item.
  template.SetValue (TextCell.TextColorProperty, Color.Red);

  itemsView.ItemTemplate = template;
  itemsView.ItemsSource = new[] {
    new Person { FullName = "James Smith", Address = "404 Nowhere Street" },
    new Person { FullName = "John Doe", Address = "404 Nowhere Ave" }
  };
}

Şunlara uygulanır

Ayrıca bkz.