ItemsView<TVisual>.ItemTemplate 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置要应用于 ItemsSource 的 DataTemplate。
public Xamarin.Forms.DataTemplate ItemTemplate { get; set; }
member this.ItemTemplate : Xamarin.Forms.DataTemplate with get, set
属性值
DataTemplate的 ItemsView<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" }
};
}