Editare

Partajați prin


ItemsControl.ItemsSource Property

Definition

Gets or sets a collection used to generate the content of the 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

Property Value

A collection that is used to generate the content of the ItemsControl. The default is null.

Attributes

Remarks

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

A common scenario is to use an ItemsControl such as a ListBox, ListView, or TreeView to display a data collection, or to bind an ItemsControl to a collection object. To bind an ItemsControl to a collection object, use the ItemsSource property. Note that the ItemsSource property supports OneWay binding by default.

When the ItemsSource property is set, the Items collection is made read-only and fixed-size.

When ItemsSource is in use, setting the property to null removes the collection and restores usage to Items, which will be an empty ItemCollection. When ItemsSource is not in use, the value of this property is null, and setting it to null has no effect.

Note

In most cases you do not need to implement your own collections. Instead, consider using ObservableCollection<T> or other existing collections. For more information, see the "Collection Objects Used as Binding Source" in Binding Sources Overview.

XAML Attribute Usage

<object ItemsSource="bindingDeclaration"/>

XAML Values

bindingDeclaration A Binding declaration. See Binding Markup Extension for more information.

Dependency Property Information

Identifier field ItemsSourceProperty
Metadata properties set to true None

Applies to