ItemsView<TVisual>.ItemTemplate 属性

定义

获取或设置要应用于 ItemsSourceDataTemplate

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

适用于

另请参阅