ListView 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。
[Xamarin.Forms.RenderWith(typeof(Xamarin.Forms.Platform._ListViewRenderer))]
public class ListView : Xamarin.Forms.ItemsView<Xamarin.Forms.Cell>, Xamarin.Forms.IElementConfiguration<Xamarin.Forms.ListView>, Xamarin.Forms.IListViewController
type ListView = class
inherit ItemsView<Cell>
interface IListViewController
interface IViewController
interface IVisualElementController
interface IElementController
interface IElementConfiguration<ListView>
- 继承
- 属性
- 实现
注解

以下示例演示了基本用法:
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace FormsGallery
{
class ListViewDemoPage : ContentPage
{
class Person
{
public Person(string name, DateTime birthday, Color favoriteColor)
{
this.Name = name;
this.Birthday = birthday;
this.FavoriteColor = favoriteColor;
}
public string Name { private set; get; }
public DateTime Birthday { private set; get; }
public Color FavoriteColor { private set; get; }
};
public ListViewDemoPage()
{
Label header = new Label
{
Text = "ListView",
FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
HorizontalOptions = LayoutOptions.Center
};
// Define some data.
List<Person> people = new List<Person>
{
new Person("Abigail", new DateTime(1975, 1, 15), Color.Aqua),
new Person("Bob", new DateTime(1976, 2, 20), Color.Black),
// ...etc.,...
new Person("Yvonne", new DateTime(1987, 1, 10), Color.Purple),
new Person("Zachary", new DateTime(1988, 2, 5), Color.Red)
};
// Create the ListView.
ListView listView = new ListView
{
// Source of data items.
ItemsSource = people,
// Define template for displaying each item.
// (Argument of DataTemplate constructor is called for
// each item; it must return a Cell derivative.)
ItemTemplate = new DataTemplate(() =>
{
// Create views with bindings for displaying each property.
Label nameLabel = new Label();
nameLabel.SetBinding(Label.TextProperty, "Name");
Label birthdayLabel = new Label();
birthdayLabel.SetBinding(Label.TextProperty,
new Binding("Birthday", BindingMode.OneWay,
null, null, "Born {0:d}"));
BoxView boxView = new BoxView();
boxView.SetBinding(BoxView.ColorProperty, "FavoriteColor");
// Return an assembled ViewCell.
return new ViewCell
{
View = new StackLayout
{
Padding = new Thickness(0, 5),
Orientation = StackOrientation.Horizontal,
Children =
{
boxView,
new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Spacing = 0,
Children =
{
nameLabel,
birthdayLabel
}
}
}
}
};
})
};
// Accomodate iPhone status bar.
this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
// Build the page.
this.Content = new StackLayout
{
Children =
{
header,
listView
}
};
}
}
}
构造函数
| 名称 | 说明 |
|---|---|
| ListView() |
创建并初始化 ListView 类的新实例。 |
| ListView(ListViewCachingStrategy) |
使用指定的缓存策略创建和初始化类的新实例 ListView 。 |
字段
| 名称 | 说明 |
|---|---|
| FooterProperty |
Footer 属性的后备存储。 |
| FooterTemplateProperty |
FooterTemplate 属性的后备存储。 |
| GroupHeaderTemplateProperty |
标识 GroupHeaderTemplate 属性。 |
| HasUnevenRowsProperty |
标识 HasUnevenRowsProperty 属性。 |
| HeaderProperty |
Header 属性的后备存储。 |
| HeaderTemplateProperty |
HeaderTemplate 属性的后备存储。 |
| HorizontalScrollBarVisibilityProperty |
字段的后盾存储 HorizontalScrollBarVisibility 。 |
| IsGroupingEnabledProperty |
标识 IsGroupingEnabledProperty 属性。 |
| IsPullToRefreshEnabledProperty |
IsPullToRefreshEnabled 属性的后备存储。 |
| IsRefreshingProperty |
IsRefreshing 属性的后备存储。 |
| RefreshCommandProperty |
RefreshCommand 属性的后备存储。 |
| RefreshControlColorProperty |
字段的后盾存储 RefreshControlColor 。 |
| RowHeightProperty |
属性的后盾存储 RowHeightProperty 。 |
| SelectedItemProperty |
标识 SelectedItemProperty 属性。 |
| SelectionModeProperty |
SelectionMode 属性的后备存储。 |
| SeparatorColorProperty |
SeparatorColor 属性的后备存储。 |
| SeparatorVisibilityProperty |
SeparatorVisibility 属性的后备存储。 |
| VerticalScrollBarVisibilityProperty |
字段的后盾存储 VerticalScrollBarVisibility 。 |
属性
| 名称 | 说明 |
|---|---|
| AnchorX |
获取或设置相对于元素边界的任何转换的中心点的 X 组件。 这是一种可绑定属性。 (继承自 VisualElement) |
| AnchorY |
获取或设置相对于元素边界的任何转换的中心点的 Y 分量。 这是一种可绑定属性。 (继承自 VisualElement) |
| AutomationId |
获取或设置允许自动化框架查找此元素并与其交互的值。 (继承自 Element) |
| Background |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 VisualElement) |
| BackgroundColor |
获取或设置将填充 VisualElement 背景的颜色。 这是一种可绑定属性。 (继承自 VisualElement) |
| Batched |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| Behaviors |
获取与此元素关联的行为列表。 这是一种可绑定属性。 (继承自 VisualElement) |
| BindingContext |
获取或设置一个对象,该对象包含由属于此 BindableObject属性的绑定属性所面向的属性。 (继承自 BindableObject) |
| Bounds |
获取元素的边界。 (继承自 VisualElement) |
| CachingStrategy |
供Xamarin内部使用。窗体平台。 |
| class |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 NavigableElement) |
| ClassId |
获取或设置用于标识语义相似元素集合的值。 (继承自 Element) |
| Clip |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 VisualElement) |
| DisableLayout |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| Dispatcher |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 BindableObject) |
| EffectControlProvider |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| Effects |
应用于此项的效果的列表。 (继承自 Element) |
| FlowDirection |
获取或设置布局流方向。 (继承自 VisualElement) |
| Footer |
获取或设置将显示在列表视图底部的字符串、绑定或视图。 |
| FooterElement |
供Xamarin内部使用。窗体平台。 |
| FooterTemplate |
获取或设置要用于格式化数据对象的数据模板,以在列表视图的底部显示。 |
| GestureController |
获取视图的手势控制器。 (继承自 View) |
| GestureRecognizers |
与此视图关联的手势识别器的集合。 (继承自 View) |
| GroupDisplayBinding |
获取或设置要用于显示组标头的绑定。 |
| GroupHeaderTemplate |
获取或设置组标头的 DataTemplate。 |
| GroupShortNameBinding |
获取或设置要在分组跳转列表中显示的名称的绑定。 |
| HasUnevenRows |
获取或设置一个布尔值,该值指示此 ListView 元素是否具有不均匀的行。 |
| Header |
获取或设置将显示在列表视图顶部的字符串、绑定或视图。 |
| HeaderElement |
供Xamarin内部使用。窗体平台。 |
| HeaderTemplate |
获取或设置要用于格式化数据对象的数据模板,以在列表视图的顶部显示。 |
| Height |
获取此元素的当前呈现高度。 这是一种只读可绑定属性。 (继承自 VisualElement) |
| HeightRequest |
获取或设置此元素所需的高度替代。 (继承自 VisualElement) |
| HorizontalOptions |
获取或设置 LayoutOptions 定义元素在布局周期中的布局方式。 这是一种可绑定属性。 (继承自 View) |
| HorizontalScrollBarVisibility |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 |
| Id |
获取一个值,该值可用于通过应用程序运行唯一标识元素。 (继承自 Element) |
| InputTransparent |
获取或设置一个值,该值指示是否应在用户交互周期中涉及此元素。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsEnabled |
获取或设置一个值,该值指示是否在用户界面中启用此元素。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsFocused |
获取一个值,该值指示当前是否聚焦此元素。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsGroupingEnabled |
获取或设置是否为 ListView 启用分组。 |
| IsInNativeLayout |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| IsNativeStateConsistent |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| IsPlatformEnabled |
供Xamarin内部使用。窗体平台。 (继承自 VisualElement) |
| IsPullToRefreshEnabled |
获取或设置一个值,该值指示用户是否可以向下轻扫以刷新应用程序。 |
| IsRefreshing |
获取或设置一个值,该值指示列表视图当前是否正在刷新。 |
| IsTabStop |
获取或设置一个值,该值指示此元素是否包含在选项卡导航中。 这是一种可绑定属性。 (继承自 VisualElement) |
| IsVisible |
获取或设置一个值,该值确定此元素是否应是可视化树的一部分。 这是一种可绑定属性。 (继承自 VisualElement) |
| ItemsSource |
获取或设置模板和显示项的源。 (继承自 ItemsView<TVisual>) |
| ItemTemplate |
获取或设置DataTemplate应用于 .ItemsSource (继承自 ItemsView<TVisual>) |
| LogicalChildren |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| Margin |
获取或设置视图的边距。 (继承自 View) |
| MinimumHeightRequest |
获取或设置一个值,该值覆盖元素在布局期间请求的最小高度。 (继承自 VisualElement) |
| MinimumWidthRequest |
获取或设置一个值,该值覆盖元素在布局期间请求的最小宽度。 (继承自 VisualElement) |
| Navigation |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 NavigableElement) |
| NavigationProxy |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 NavigableElement) |
| Opacity |
获取或设置呈现元素时应用于元素的不透明度值。 这是一种可绑定属性。 (继承自 VisualElement) |
| Parent |
获取或设置元素的父元素。 (继承自 Element) |
| ParentView |
已过时.
获取作为此元素最接近的上级元素的 VisualElement元素。 (继承自 Element) |
| Platform |
已过时.
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 Element) |
| RealParent |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| RefreshAllowed |
供Xamarin内部使用。窗体平台。 |
| RefreshCommand |
获取或设置在列表视图进入刷新状态时运行的命令。 |
| RefreshControlColor |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 |
| Resources |
获取或设置本地资源字典。 (继承自 VisualElement) |
| Rotation |
获取或设置呈现元素时围绕 Z 轴(仿射旋转)的旋转角度(以度为单位)。 (继承自 VisualElement) |
| RotationX |
获取或设置呈现元素时围绕 X 轴(透视旋转)的旋转角度(以度为单位)。 (继承自 VisualElement) |
| RotationY |
获取或设置呈现元素时围绕 Y 轴(透视旋转)的旋转角度(以度为单位)。 (继承自 VisualElement) |
| RowHeight |
获取或设置一个值,该值表示行的高度。 |
| Scale |
获取或设置应用于元素的比例因子。 (继承自 VisualElement) |
| ScaleX |
获取或设置要应用于 X 方向的缩放值。 (继承自 VisualElement) |
| ScaleY |
获取或设置要应用于 Y 方向的缩放值。 (继承自 VisualElement) |
| SelectedItem |
获取或设置 ItemsSource 中的当前选定项。 |
| SelectionMode |
获取或设置一个值,用于控制是否可以选择项以及选择多少个项。 |
| SeparatorColor |
获取或设置分隔列表项的栏的颜色。 |
| SeparatorVisibility |
获取或设置一个值,该值指示分隔符在项之间是否可见。 |
| Style |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 NavigableElement) |
| StyleClass |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 NavigableElement) |
| StyleId |
获取或设置用于唯一地标识元素的用户定义的值。 (继承自 Element) |
| TabIndex |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 VisualElement) |
| TemplatedItems |
获取模板化项的列表。 (继承自 ItemsView<TVisual>) |
| TranslationX |
获取或设置元素的 X 转换增量。 (继承自 VisualElement) |
| TranslationY |
获取或设置元素的 Y 转换增量。 (继承自 VisualElement) |
| Triggers |
获取与此元素关联的触发器列表。 这是一种可绑定属性。 (继承自 VisualElement) |
| VerticalOptions |
获取或设置 LayoutOptions 定义元素在布局周期中的布局方式。 这是一种可绑定属性。 (继承自 View) |
| VerticalScrollBarVisibility |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 |
| Visual |
以垂直列表的形式显示数据集合的 ItemsView<TVisual>。 (继承自 VisualElement) |
| Width |
获取此元素的当前呈现宽度。 这是一种只读可绑定属性。 (继承自 VisualElement) |
| WidthRequest |
获取或设置此元素的所需宽度重写。 (继承自 VisualElement) |
| X |
获取此元素的当前 X 位置。 这是一种只读可绑定属性。 (继承自 VisualElement) |
| Y |
获取此元素的当前 Y 位置。 这是一种只读可绑定属性。 (继承自 VisualElement) |
方法
活动
显式接口实现
| 名称 | 说明 |
|---|---|
| IDynamicResourceHandler.SetDynamicResource(BindableProperty, String) |
供Xamarin内部使用。窗体平台。 (继承自 BindableObject) |
| IElementController.SetValueFromRenderer(BindableProperty, Object) |
供Xamarin内部使用。窗体平台。 (继承自 Element) |
| IGestureController.CompositeGestureRecognizers |
供Xamarin内部使用。窗体平台。 (继承自 View) |
| IItemsView<TVisual>.CreateDefault(Object) |
使用 创建默认 TVisual |
| IItemsView<TVisual>.SetupContent(TVisual, Int32) |
CInternal 仅使用。 (继承自 ItemsView<TVisual>) |
| IItemsView<TVisual>.UnhookContent(TVisual) |
仅供内部使用。 (继承自 ItemsView<TVisual>) |
| INameScope.RegisterName(String, Object) |
仅供内部使用。 (继承自 Element) |
| ITemplatedItemsView<TVisual>.ListProxy |
此接口供平台呈现器内部使用。 (继承自 ItemsView<TVisual>) |
| ITemplatedItemsView<TVisual>.TemplatedItems |
此接口供平台呈现器内部使用。 (继承自 ItemsView<TVisual>) |
| IVisualElementController.EffectiveFlowDirection |
获取平台上元素的有效视觉流方向,同时考虑区域设置和逻辑流设置。 (继承自 VisualElement) |
| IVisualElementController.InvalidateMeasure(InvalidationTrigger) |
此方法供内部使用。 (继承自 VisualElement) |