ItemsControl.ItemsSource 屬性

定義

取得或設定用來產生 ItemsControl 之內容的集合。

C#
[System.ComponentModel.Bindable(true)]
public System.Collections.IEnumerable ItemsSource { get; set; }

屬性值

用來產生 ItemsControl 之內容的集合。 預設為 null

屬性

備註

內容模型: 這個屬性可用來將專案加入至 ItemsControl

常見的案例是使用 ItemsControlListView、 或 TreeView 之類的 ListBox來顯示數據收集,或系結ItemsControl至集合物件。 若要將 系結 ItemsControl 至集合物件,請使用 ItemsSource 屬性。 請注意, ItemsSource 屬性預設支援 OneWay 系結。

ItemsSource設定 屬性時,Items集合會變成唯讀且固定大小。

當 正在使用時 ItemsSource ,將 屬性設定為 null 會移除集合,並將使用方式還原為 Items,這會是空 ItemCollection的 。 當 ItemsSource 不在使用中時,這個屬性的值是 null,並將它設定為 null 沒有作用。

備註

在大部分情況下,您不需要實作自己的集合。 相反地,請考慮使用 ObservableCollection<T> 或其他現有的集合。 如需詳細資訊,請參閱系結 來源概觀中的。

XAML Attribute Usage

<object ItemsSource="bindingDeclaration"/>

XAML 值

bindingDeclaration 宣告 Binding 。 如需詳細資訊,請參閱 系結標記延伸

相依性屬性資訊

標識元欄位 ItemsSourceProperty
設定為的元數據屬性 true

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9