Share via


ItemsControl.ItemsSource 属性

定义

获取或设置用于生成 ItemsControl 的内容的集合。

public:
 property System::Collections::IEnumerable ^ ItemsSource { System::Collections::IEnumerable ^ get(); void set(System::Collections::IEnumerable ^ value); };
[System.ComponentModel.Bindable(true)]
public System.Collections.IEnumerable ItemsSource { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ItemsSource : System.Collections.IEnumerable with get, set
Public Property ItemsSource As IEnumerable

属性值

用于生成 ItemsControl 的内容的集合。 默认值为 null

属性

注解

内容模型: 此属性可用于将项添加到 ItemsControl

一种常见方案是使用 ItemsControl 、 或 TreeViewListBoxListView来显示数据收集,或将 绑定到ItemsControl集合对象。 若要将 绑定到 ItemsControl 集合对象,请使用 ItemsSource 属性。 请注意, ItemsSource 属性默认支持 OneWay 绑定。

ItemsSource设置 属性后,Items集合将设置为只读且大小固定。

使用 时 ItemsSource ,将 属性设置为 null 会删除集合并将使用情况还原到 Items,这将为空 ItemCollection。 当 ItemsSource 未使用 时,此属性 null的值为 ,将其设置为 null 不起作用。

注意

在大多数情况下,无需实现自己的集合。 相反,请考虑使用 ObservableCollection<T> 或其他现有集合。 有关详细信息,请参阅绑定源概述中的“用作绑定 源的集合对象”。

XAML 属性用法

<object ItemsSource="bindingDeclaration"/>

XAML 值

bindingDeclaration 声明 Binding 。 有关详细信息 ,请参阅绑定标记扩展

依赖项属性信息

标识符字段 ItemsSourceProperty
元数据属性设置为 true

适用于