Skip to main content
ItemCollection Class
 

Holds the list of items that constitute the content of an ItemsControl.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

SystemObject
   System.Windows.ThreadingDispatcherObject
     System.Windows.DataCollectionView
      System.Windows.ControlsItemCollection

[LocalizabilityAttribute(LocalizationCategory.Ignore)]
public sealed class ItemCollection : CollectionView, IList, ICollection, 
	IEnumerable, IEditableCollectionViewAddNewItem, IEditableCollectionView, 
	ICollectionViewLiveShaping, IItemProperties, IWeakEventListener
[LocalizabilityAttribute(LocalizationCategory::Ignore)]
public ref class ItemCollection sealed : CollectionView, IList, 
	ICollection, IEnumerable, IEditableCollectionViewAddNewItem, 
	IEditableCollectionView, ICollectionViewLiveShaping, IItemProperties, 
	IWeakEventListener
[<Sealed>]
[<LocalizabilityAttribute(LocalizationCategory.Ignore)>]
type ItemCollection = 
    class
        inherit CollectionView
        interface IList
        interface ICollection
        interface IEnumerable
        interface IEditableCollectionViewAddNewItem
        interface IEditableCollectionView
        interface ICollectionViewLiveShaping
        interface IItemProperties
        interface IWeakEventListener
    end
<LocalizabilityAttribute(LocalizationCategory.Ignore)>
Public NotInheritable Class ItemCollection
	Inherits CollectionView
	Implements IList, ICollection, IEnumerable, IEditableCollectionViewAddNewItem,
	IEditableCollectionView, ICollectionViewLiveShaping, IItemProperties,
	IWeakEventListener
NameDescription
System_CAPS_pubproperty

Gets a value that indicates whether the collection view supports turning filtering data in real time on or off.

System_CAPS_pubproperty

Gets a value that indicates whether the collection view supports turning grouping data in real time on or off.

System_CAPS_pubproperty

Gets a value that indicates whether the collection view supports turning sorting data in real time on or off.

System_CAPS_pubproperty

Gets a value that indicates whether this collection view supports filtering.(Overrides .)

System_CAPS_pubproperty

Gets a value that indicates whether this collection view supports grouping.(Overrides .)

System_CAPS_pubproperty

Gets a value that indicates whether this collection view supports sorting.(Overrides .)

System_CAPS_pubproperty

Returns an object that you can use to compare items in the view.(Inherited from CollectionView.)

System_CAPS_pubproperty

Gets the number of records in the collection. (Overrides .)

System_CAPS_pubproperty

Gets or sets the culture information to use during sorting.(Inherited from CollectionView.)

System_CAPS_pubproperty

Gets the current item in the view.(Overrides .)

System_CAPS_pubproperty

Gets the ordinal position of the current item within the view.(Overrides .)

System_CAPS_pubproperty

Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)

System_CAPS_pubproperty

Gets or sets a callback used to determine if an item is suitable for inclusion in the view.(Overrides .)

System_CAPS_pubproperty

Gets a collection of GroupDescription objects that defines how to group the items.(Overrides .)

System_CAPS_pubproperty

Gets the top-level groups that are constructed according to the .(Overrides .)

System_CAPS_pubproperty

Gets a value that indicates whether the current item of the view is beyond the end of the collection.(Overrides .)

System_CAPS_pubproperty

Gets a value that indicates whether the current item of the view is beyond the beginning of the collection.(Overrides .)

System_CAPS_pubproperty

Gets a value that indicates whether the resulting (filtered) view is empty.(Overrides .)

System_CAPS_pubproperty

Gets a value that indicates whether any object is subscribing to the events of this CollectionView.(Inherited from CollectionView.)

System_CAPS_pubproperty

Gets or sets a value that indicates whether filtering data in real time is enabled.

System_CAPS_pubproperty

Gets or sets a value that indicates whether grouping data in real time is enabled.

System_CAPS_pubproperty

Gets or sets a value that indicates whether sorting in real time is enabled.

System_CAPS_pubproperty

Gets or sets the item at the given zero-based index.

System_CAPS_pubproperty

Gets a collection of strings that specify the properties that participate in filtering data in real time.

System_CAPS_pubproperty

Gets a collection of strings that specify the properties that participate in grouping data in real time.

System_CAPS_pubproperty

Gets a collection of strings that specify the properties that participate in sorting data in real time.

System_CAPS_pubproperty

Gets a value that indicates whether the collection needs to be refreshed.(Overrides .)

System_CAPS_pubproperty

Gets a collection of SortDescription objects that describe how the items in the collection are sorted in the view.(Overrides .)

System_CAPS_pubproperty

Gets the unsorted and unfiltered collection that underlies this collection view. (Overrides .)

NameDescription
System_CAPS_pubmethod Add

Adds an item to the ItemCollection.

System_CAPS_pubmethod CheckAccess

Determines whether the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

System_CAPS_pubmethod Clear

Clears the collection and releases the references on all items currently in the collection.

System_CAPS_pubmethod Contains

Returns a value that indicates whether the specified item is in this view.(Overrides CollectionViewContains.)

System_CAPS_pubmethod CopyTo

Copies the elements of the collection to an array, starting at a particular array index.

System_CAPS_pubmethod DeferRefresh

Enters a defer cycle that you can use to merge changes to the view and delay automatic refresh.(Overrides CollectionViewDeferRefresh.)

System_CAPS_pubmethod DetachFromSourceCollection

Removes the reference to the underlying collection from the CollectionView.(Inherited from CollectionView.)

System_CAPS_pubmethod Equals

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethod GetHashCode

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethod GetItemAt

Returns the item at the specified zero-based index in this view.(Overrides CollectionViewGetItemAt.)

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod IndexOf

Returns the index in this collection where the specified item is located. (Overrides CollectionViewIndexOf.)

System_CAPS_pubmethod Insert

Inserts an element into the collection at the specified index.

System_CAPS_pubmethod MoveCurrentTo

Sets the specified item in the collection as the .(Overrides CollectionViewMoveCurrentTo.)

System_CAPS_pubmethod MoveCurrentToFirst

Sets the first item in the view as the .(Overrides CollectionViewMoveCurrentToFirst.)

System_CAPS_pubmethod MoveCurrentToLast

Sets the last item in the view as the .(Overrides CollectionViewMoveCurrentToLast.)

System_CAPS_pubmethod MoveCurrentToNext

Sets the item after the in the view as the .(Overrides CollectionViewMoveCurrentToNext.)

System_CAPS_pubmethod MoveCurrentToPosition

Sets the item at the specified index to be the in the view.(Overrides CollectionViewMoveCurrentToPosition.)

System_CAPS_pubmethod MoveCurrentToPrevious

Sets the item before the in the view as the .(Overrides CollectionViewMoveCurrentToPrevious.)

System_CAPS_pubmethod PassesFilter

Returns a value that indicates whether the specified item belongs to this view.(Overrides CollectionViewPassesFilter.)

System_CAPS_pubmethod Refresh

Re-creates the view.(Inherited from CollectionView.)

System_CAPS_pubmethod Remove

Removes the specified item reference from the collection or view.

System_CAPS_pubmethod RemoveAt

Removes the item at the specified index of the collection or view.

System_CAPS_pubmethod ToString

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethod VerifyAccess

Enforces that the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

NameDescription
System_CAPS_pubevent CurrentChanged

Occurs after the has changed.(Inherited from CollectionView.)

System_CAPS_pubevent CurrentChanging

Occurs when the is changing.(Inherited from CollectionView.)

NameDescription
System_CAPS_pubinterface System_CAPS_privevent INotifyCollectionChangedCollectionChanged

Occurs when the view has changed.(Inherited from CollectionView.)

System_CAPS_pubinterface System_CAPS_privevent INotifyPropertyChangedPropertyChanged

Occurs when a property value changes.(Inherited from CollectionView.)

System_CAPS_pubinterface System_CAPS_privmethod IEnumerableGetEnumerator

Returns an IEnumerator object that you can use to enumerate the items in the view.(Inherited from CollectionView.)

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewAddNew

Adds a new item to the collection.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewCancelEdit

Ends the edit transaction and, if possible, restores the original value to the item.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewCancelNew

Ends the add transaction and discards the pending new item.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewCommitEdit

Ends the edit transaction and saves the pending changes.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewCommitNew

Ends the add transaction and saves the pending new item.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewEditItem

Begins an edit transaction of the specified item.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewRemove

Removes the specified item from the collection.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewRemoveAt

Removes the item at the specified position from the collection.

System_CAPS_pubinterface System_CAPS_privmethod IEditableCollectionViewAddNewItemAddNewItem

Adds the specified object to the collection.

System_CAPS_pubinterface System_CAPS_privmethod IWeakEventListenerReceiveWeakEvent

Receives events from the centralized event manager.

System_CAPS_pubinterface System_CAPS_privproperty

This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

System_CAPS_pubinterface System_CAPS_privproperty

This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

System_CAPS_pubinterface System_CAPS_privproperty

This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

System_CAPS_pubinterface System_CAPS_privproperty

This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value that indicates whether a new item can be added to the collection.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value that indicates whether an item can be removed from the collection.

System_CAPS_pubinterface System_CAPS_privproperty

Gets the item that is being added during the current add transaction.

System_CAPS_pubinterface System_CAPS_privproperty

Gets the item in the collection that is being edited.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value that indicates whether an add transaction is in progress.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value that indicates whether an edit transaction is in progress.

System_CAPS_pubinterface System_CAPS_privproperty

Gets or sets the position of the new item placeholder in the collection view.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a value that indicates whether a specified object can be added to the collection.

System_CAPS_pubinterface System_CAPS_privproperty

Gets a collection that contains information about the properties that are available on the items in a collection.

NameDescription
System_CAPS_pubmethod AsParallel

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethod AsQueryable

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethod Cast

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethod OfType

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

ItemCollection maintains a collection of items such as strings, objects, XML nodes, elements, and other collections. An ItemsControl uses the data in the ItemCollection to generate its content. If you want to aggregate more than one collection, assign a CompositeCollection to the property of your ItemsControl.

Use either the property or the property to specify the collection that should be used to generate the content of your ItemsControl. When the property is set, the collection will be made read-only and fixed-size. This means that if you are using the property, you cannot add, delete, or change items in the ItemCollection directly.

ItemCollection is a CollectionView and therefore provides collection view functionalities, such as sorting, grouping, and filtering. For more information, see , , and .

For more information about collection views, see Data Binding Overview.

If you have an ItemsControl, such as a ListBox that has content, you can use the property to access the ItemCollection, which is a view. Because it is a view, you can then use the view-related functionalities such as sorting, filtering, and grouping. Note that when ItemsSource is set, the view operations delegate to the view over the ItemsSource collection. Therefore, the ItemCollection supports sorting, filtering, and grouping only if the delegated view supported them.

The following example shows how to sort the content of a ListBox named myListBox. In this example, Content is the name of the property to sort by.

myListBox.Items.SortDescriptions.Add(
    new SortDescription("Content", ListSortDirection.Descending));
myListBox.Items.SortDescriptions.Add(New SortDescription("Content", ListSortDirection.Descending))

When you do this, the view might or might not be the default view, depending on how the data is set up on your ItemsControl. For example, when the property is bound to a CollectionViewSource, the view that you obtain using the property is not the default view.

If your ItemsControl is bound (you are using the property), then you can do the following to get the default view:

CollectionView myView;
Private myView As CollectionView
myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);
myView = CType(CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource), CollectionView)

Alternately, you can specify filtering, sorting, and grouping criteria in XAML using  CollectionViewSource.

.NET Framework
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top