ItemsView<TVisual>.ItemTemplate 속성

정의

ItemsSource에 적용할 DataTemplate을 가져오거나 설정합니다.

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

속성 값

, 또는 에 대한 입니다 DataTemplateItemsView<TVisual>. null

설명

ItemTemplate은 에서 ItemsSource개체의 시각적 모양을 정의하는 데 사용됩니다. 항목 템플릿을 통해 제공된 사용자 개체에 대한 데이터 바인딩을 설정하여 시각적 개체를 자동으로 채우고 사용자 개체의 변경 내용에 응답할 수 있습니다.

항목 템플릿이 null인 경우 Xamarin.Forms.ItemsView'1.CreateDefault(System.Object)가 호출되고 결과가 시각적 개체로 사용됩니다.

이 예제에서는 간단한 사용자 개체에 대해 에 TextCell 대한 템플릿을 만듭니다.

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

적용 대상

추가 정보