ItemsView<TVisual>.ItemTemplate ItemsView<TVisual>.ItemTemplate Property

Definition

Gets or sets the DataTemplate to apply to the ItemsSource.

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

Remarks

The ItemTemplate is used to define the visual appearance of objects from the ItemsSource. Through the item template you can set up data bindings to the user objects supplied to automatically fill in the visual and respond to any changes in the user object.

If the item template is null, CreateDefault(Object) is called and the result is used as the visual.

In this example, a template for a TextCell is created for a simple user object.


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

Applies to

See Also