Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ItemCollection Class

 

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

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

System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.Data.CollectionView
      System.Windows.Controls.ItemCollection

[LocalizabilityAttribute(LocalizationCategory.Ignore)]
public sealed class ItemCollection : CollectionView, IList, ICollection, 
	IEnumerable, IEditableCollectionViewAddNewItem, IEditableCollectionView, 
	ICollectionViewLiveShaping, IItemProperties, IWeakEventListener

NameDescription
System_CAPS_pubpropertyCanChangeLiveFiltering

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

System_CAPS_pubpropertyCanChangeLiveGrouping

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

System_CAPS_pubpropertyCanChangeLiveSorting

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

System_CAPS_pubpropertyCanFilter

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

System_CAPS_pubpropertyCanGroup

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

System_CAPS_pubpropertyCanSort

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

System_CAPS_pubpropertyComparer

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

System_CAPS_pubpropertyCount

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

System_CAPS_pubpropertyCulture

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

System_CAPS_pubpropertyCurrentItem

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

System_CAPS_pubpropertyCurrentPosition

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

System_CAPS_pubpropertyDispatcher

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

System_CAPS_pubpropertyFilter

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

System_CAPS_pubpropertyGroupDescriptions

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

System_CAPS_pubpropertyGroups

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

System_CAPS_pubpropertyIsCurrentAfterLast

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

System_CAPS_pubpropertyIsCurrentBeforeFirst

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

System_CAPS_pubpropertyIsEmpty

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

System_CAPS_pubpropertyIsInUse

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

System_CAPS_pubpropertyIsLiveFiltering

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

System_CAPS_pubpropertyIsLiveGrouping

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

System_CAPS_pubpropertyIsLiveSorting

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

System_CAPS_pubpropertyItem[Int32]

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

System_CAPS_pubpropertyLiveFilteringProperties

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

System_CAPS_pubpropertyLiveGroupingProperties

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

System_CAPS_pubpropertyLiveSortingProperties

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

System_CAPS_pubpropertyNeedsRefresh

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

System_CAPS_pubpropertySortDescriptions

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

System_CAPS_pubpropertySourceCollection

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

NameDescription
System_CAPS_pubmethodAdd(Object)

Adds an item to the ItemCollection.

System_CAPS_pubmethodCheckAccess()

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

System_CAPS_pubmethodClear()

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

System_CAPS_pubmethodContains(Object)

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

System_CAPS_pubmethodCopyTo(Array, Int32)

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

System_CAPS_pubmethodDeferRefresh()

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

System_CAPS_pubmethodDetachFromSourceCollection()

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

System_CAPS_pubmethodEquals(Object)

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

System_CAPS_pubmethodGetHashCode()

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

System_CAPS_pubmethodGetItemAt(Int32)

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

System_CAPS_pubmethodGetType()

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

System_CAPS_pubmethodIndexOf(Object)

Returns the index in this collection where the specified item is located. (Overrides CollectionView.IndexOf(Object).)

System_CAPS_pubmethodInsert(Int32, Object)

Inserts an element into the collection at the specified index.

System_CAPS_pubmethodMoveCurrentTo(Object)

Sets the specified item in the collection as the CurrentItem.(Overrides CollectionView.MoveCurrentTo(Object).)

System_CAPS_pubmethodMoveCurrentToFirst()

Sets the first item in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToFirst().)

System_CAPS_pubmethodMoveCurrentToLast()

Sets the last item in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToLast().)

System_CAPS_pubmethodMoveCurrentToNext()

Sets the item after the CurrentItem in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToNext().)

System_CAPS_pubmethodMoveCurrentToPosition(Int32)

Sets the item at the specified index to be the CurrentItem in the view.(Overrides CollectionView.MoveCurrentToPosition(Int32).)

System_CAPS_pubmethodMoveCurrentToPrevious()

Sets the item before the CurrentItem in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToPrevious().)

System_CAPS_pubmethodPassesFilter(Object)

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

System_CAPS_pubmethodRefresh()

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

System_CAPS_pubmethodRemove(Object)

Removes the specified item reference from the collection or view.

System_CAPS_pubmethodRemoveAt(Int32)

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

System_CAPS_pubmethodToString()

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

System_CAPS_pubmethodVerifyAccess()

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

NameDescription
System_CAPS_pubeventCurrentChanged

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

System_CAPS_pubeventCurrentChanging

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

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_priveventINotifyCollectionChanged.CollectionChanged

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

System_CAPS_pubinterfaceSystem_CAPS_priveventINotifyPropertyChanged.PropertyChanged

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

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

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

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.AddNew()

Adds a new item to the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.CancelEdit()

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

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.CancelNew()

Ends the add transaction and discards the pending new item.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.CommitEdit()

Ends the edit transaction and saves the pending changes.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.CommitNew()

Ends the add transaction and saves the pending new item.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.EditItem(Object)

Begins an edit transaction of the specified item.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.Remove(Object)

Removes the specified item from the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionView.RemoveAt(Int32)

Removes the item at the specified position from the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEditableCollectionViewAddNewItem.AddNewItem(Object)

Adds the specified object to the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIWeakEventListener.ReceiveWeakEvent(Type, Object, EventArgs)

Receives events from the centralized event manager.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.IsSynchronized

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.SyncRoot

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIList.IsFixedSize

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIList.IsReadOnly

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.CanAddNew

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.CanCancelEdit

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.CanRemove

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.CurrentAddItem

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.CurrentEditItem

Gets the item in the collection that is being edited.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.IsAddingNew

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.IsEditingItem

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionView.NewItemPlaceholderPosition

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIEditableCollectionViewAddNewItem.CanAddNewItem

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

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIItemProperties.ItemProperties

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

NameDescription
System_CAPS_pubmethodAsParallel()

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

System_CAPS_pubmethodAsQueryable()

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

System_CAPS_pubmethodCast<TResult>()

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

System_CAPS_pubmethodOfType<TResult>()

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 ItemsSource property of your ItemsControl.

Use either the Items property or the ItemsSource property to specify the collection that should be used to generate the content of your ItemsControl. When the ItemsSource property is set, the Items collection will be made read-only and fixed-size. This means that if you are using the ItemsSource 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 SortDescriptions, Filter, and GroupDescriptions.

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 Items 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));

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 ItemsSource property is bound to a CollectionViewSource, the view that you obtain using the Items property is not the default view.

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

CollectionView myView;
myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);

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
Show:
© 2016 Microsoft