ItemsControl.ItemsSource 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定用來產生 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 、ListView、 或 TreeView 之類的 ListBox來顯示數據收集,或系結ItemsControl至集合物件。 若要將 系結 ItemsControl 至集合物件,請使用 ItemsSource 屬性。 請注意, ItemsSource 屬性預設支援 OneWay 系結。
ItemsSource設定 屬性時,Items集合會變成唯讀且固定大小。
當 正在使用時 ItemsSource ,將 屬性設定為 null
會移除集合,並將使用方式還原為 Items,這會是空 ItemCollection的 。 當 ItemsSource 不在使用中時,這個屬性的值是 null
,並將它設定為 null
沒有作用。
備註
在大部分情況下,您不需要實作自己的集合。 相反地,請考慮使用 ObservableCollection<T> 或其他現有的集合。 如需詳細資訊,請參閱系結 來源概觀中的。
<object ItemsSource="bindingDeclaration"/>
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 |