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

属性值

IEnumerable

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

属性

注解

Content Model: This property may be used to add items to an ItemsControl.

常见方案是使用ItemsControl例如、ListBoxListViewTreeView显示数据收集,或绑定到ItemsControl集合对象。 若要绑定到 ItemsControl 集合对象,请使用 ItemsSource 该属性。 请注意,默认情况下,该 ItemsSource 属性支持 OneWay 绑定。

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

使用时 ItemsSource ,将属性 null 设置为删除集合并将用法还原为 ItemsItemCollection。 未使用时 ItemsSource ,此属性的值为 null,并将其 null 设置为无效。

备注

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

XAML 属性用法

<object ItemsSource="bindingDeclaration"/>  

XAML 值

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

依赖项属性信息

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

适用于