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

屬性

備註

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

常見的案例是使用 ItemsControl 、、 或 TreeView 之類的 ListBox ListView 來顯示資料收集,或系結 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

適用於