Export (0) Print
Expand All

ItemCollection Class

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

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

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

The ItemCollection type exposes the following members.

  NameDescription
Public propertyCanFilterGets a value that indicates whether this collection view supports filtering. (Overrides CollectionView.CanFilter.)
Public propertyCanGroupGets a value that indicates whether this collection view supports grouping. (Overrides CollectionView.CanGroup.)
Public propertyCanSortGets a value that indicates whether this collection view supports sorting. (Overrides CollectionView.CanSort.)
Public propertyComparerReturns an object that you can use to compare items in the view. (Inherited from CollectionView.)
Public propertyCountGets the number of records in the collection. (Overrides CollectionView.Count.)
Public propertyCultureGets or sets the culture information to use during sorting. (Inherited from CollectionView.)
Public propertyCurrentItemGets the current item in the view. (Overrides CollectionView.CurrentItem.)
Public propertyCurrentPositionGets the ordinal position of the current item within the view. (Overrides CollectionView.CurrentPosition.)
Public propertyDispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public propertyFilterGets or sets a callback used to determine if an item is suitable for inclusion in the view. (Overrides CollectionView.Filter.)
Public propertyGroupDescriptionsGets a collection of GroupDescription objects that defines how to group the items. (Overrides CollectionView.GroupDescriptions.)
Public propertyGroupsGets the top-level groups that are constructed according to the GroupDescriptions. (Overrides CollectionView.Groups.)
Public propertyIsCurrentAfterLastGets a value that indicates whether the current item of the view is beyond the end of the collection. (Overrides CollectionView.IsCurrentAfterLast.)
Public propertyIsCurrentBeforeFirstGets a value that indicates whether the current item of the view is beyond the beginning of the collection. (Overrides CollectionView.IsCurrentBeforeFirst.)
Protected propertyIsCurrentInSyncGets a value that indicates whether the CurrentItem is at the CurrentPosition. (Inherited from CollectionView.)
Protected propertyIsDynamicGets a value that indicates whether the underlying collection provides change notifications. (Inherited from CollectionView.)
Public propertyIsEmptyGets a value that indicates whether the resulting (filtered) view is empty. (Overrides CollectionView.IsEmpty.)
Protected propertyIsRefreshDeferredGets a value that indicates whether there is an outstanding DeferRefresh in use. (Inherited from CollectionView.)
Public propertyItemGets or sets the item at the given zero-based index.
Public propertyNeedsRefreshGets a value that indicates whether the collection needs to be refreshed. (Overrides CollectionView.NeedsRefresh.)
Public propertySortDescriptionsGets a collection of SortDescription objects that describe how the items in the collection are sorted in the view. (Overrides CollectionView.SortDescriptions.)
Public propertySourceCollectionGets the unsorted and unfiltered collection that underlies this collection view. (Overrides CollectionView.SourceCollection.)
Protected propertyUpdatedOutsideDispatcherGets a value that indicates whether it has been necessary to update the change log because a CollectionChanged notification has been received on a different thread without first entering the user interface (UI) thread dispatcher. (Inherited from CollectionView.)
Top

  NameDescription
Public methodAddAdds an item to the ItemCollection.
Public methodCheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Public methodClearClears the collection and releases the references on all items currently in the collection.
Protected methodClearChangeLogClears any pending changes from the change log. (Inherited from CollectionView.)
Public methodContainsReturns a value that indicates whether the specified item is in this view. (Overrides CollectionView.Contains(Object).)
Public methodCopyToCopies the elements of the collection to an array, starting at a particular array index.
Public methodDeferRefreshEnters a defer cycle that you can use to merge changes to the view and delay automatic refresh. (Overrides CollectionView.DeferRefresh().)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected methodGetEnumeratorReturns an object that you can use to enumerate the items in the view. (Inherited from CollectionView.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetItemAtReturns the item at the specified zero-based index in this view. (Overrides CollectionView.GetItemAt(Int32).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfReturns the index in this collection where the specified item is located. (Overrides CollectionView.IndexOf(Object).)
Public methodInsert Inserts an element into the collection at the specified index.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodMoveCurrentToSets the specified item in the collection as the CurrentItem. (Overrides CollectionView.MoveCurrentTo(Object).)
Public methodMoveCurrentToFirstSets the first item in the view as the CurrentItem. (Overrides CollectionView.MoveCurrentToFirst().)
Public methodMoveCurrentToLastSets the last item in the view as the CurrentItem. (Overrides CollectionView.MoveCurrentToLast().)
Public methodMoveCurrentToNextSets the item after the CurrentItem in the view as the CurrentItem. (Overrides CollectionView.MoveCurrentToNext().)
Public methodMoveCurrentToPositionSets the item at the specified index to be the CurrentItem in the view. (Overrides CollectionView.MoveCurrentToPosition(Int32).)
Public methodMoveCurrentToPreviousSets the item before the CurrentItem in the view as the CurrentItem. (Overrides CollectionView.MoveCurrentToPrevious().)
Protected methodOKToChangeCurrentReturns a value that indicates whether the view can change which item is the CurrentItem. (Inherited from CollectionView.)
Protected methodOnBeginChangeLoggingCalled by the base class to notify the derived class that an INotifyCollectionChanged.CollectionChanged event has been posted to the message queue. (Inherited from CollectionView.)
Protected methodOnCollectionChanged(NotifyCollectionChangedEventArgs)Raises the CollectionChanged event. (Inherited from CollectionView.)
Protected methodOnCollectionChanged(Object, NotifyCollectionChangedEventArgs)Raises the CollectionChanged event. (Inherited from CollectionView.)
Protected methodOnCurrentChangedRaises the CurrentChanged event. (Inherited from CollectionView.)
Protected methodOnCurrentChanging()Raises a CurrentChanging event that is not cancelable. (Inherited from CollectionView.)
Protected methodOnCurrentChanging(CurrentChangingEventArgs)Raises the CurrentChanging event with the specified arguments. (Inherited from CollectionView.)
Protected methodOnPropertyChangedRaises the PropertyChanged event using the specified arguments. (Inherited from CollectionView.)
Public methodPassesFilterReturns a value that indicates whether the specified item belongs to this view. (Overrides CollectionView.PassesFilter(Object).)
Protected methodProcessCollectionChangedWhen overridden in a derived class, processes a single change on the UI thread. (Inherited from CollectionView.)
Public methodRefreshRe-creates the view. (Inherited from CollectionView.)
Protected methodRefreshOrDeferRefreshes the view or specifies that the view needs to be refreshed when the defer cycle completes. (Inherited from CollectionView.)
Protected methodRefreshOverrideRe-creates the view. (Inherited from CollectionView.)
Public methodRemoveRemoves the specified item reference from the collection or view.
Public methodRemoveAtRemoves the item at the specified index of the collection or view.
Protected methodSetCurrent(Object, Int32)Sets the specified item and index as the values of the CurrentItem and CurrentPosition properties. (Inherited from CollectionView.)
Protected methodSetCurrent(Object, Int32, Int32)Sets the specified item and index as the values of the CurrentItem and CurrentPosition properties. This method can be called from a constructor of a derived class. (Inherited from CollectionView.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodVerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Top

  NameDescription
Protected eventCollectionChangedOccurs when the view has changed. (Inherited from CollectionView.)
Public eventCurrentChangedOccurs after the CurrentItem has changed. (Inherited from CollectionView.)
Public eventCurrentChangingOccurs when the CurrentItem is changing. (Inherited from CollectionView.)
Protected eventPropertyChangedOccurs when a property value has changed. (Inherited from CollectionView.)
Top

  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<TResult>Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Explicit interface implemetationPrivate propertyICollection.SyncRootThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Explicit interface implemetationPrivate methodIEditableCollectionView.AddNewAdds a new item to the collection.
Explicit interface implemetationPrivate propertyIEditableCollectionView.CanAddNewGets a value that indicates whether a new item can be added to the collection.
Explicit interface implemetationPrivate propertyIEditableCollectionView.CanCancelEditGets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object.
Explicit interface implemetationPrivate methodIEditableCollectionView.CancelEditEnds the edit transaction and, if possible, restores the original value to the item.
Explicit interface implemetationPrivate methodIEditableCollectionView.CancelNewEnds the add transaction and discards the pending new item.
Explicit interface implemetationPrivate propertyIEditableCollectionView.CanRemoveGets a value that indicates whether an item can be removed from the collection.
Explicit interface implemetationPrivate methodIEditableCollectionView.CommitEditEnds the edit transaction and saves the pending changes.
Explicit interface implemetationPrivate methodIEditableCollectionView.CommitNewEnds the add transaction and saves the pending new item.
Explicit interface implemetationPrivate propertyIEditableCollectionView.CurrentAddItemGets the item that is being added during the current add transaction.
Explicit interface implemetationPrivate propertyIEditableCollectionView.CurrentEditItemGets the item in the collection that is being edited.
Explicit interface implemetationPrivate methodIEditableCollectionView.EditItemBegins an edit transaction of the specified item.
Explicit interface implemetationPrivate propertyIEditableCollectionView.IsAddingNewGets a value that indicates whether an add transaction is in progress.
Explicit interface implemetationPrivate propertyIEditableCollectionView.IsEditingItemGets a value that indicates whether an edit transaction is in progress.
Explicit interface implemetationPrivate propertyIEditableCollectionView.NewItemPlaceholderPositionGets or sets the position of the new item placeholder in the collection view.
Explicit interface implemetationPrivate methodIEditableCollectionView.RemoveRemoves the specified item from the collection.
Explicit interface implemetationPrivate methodIEditableCollectionView.RemoveAtRemoves the item at the specified position from the collection.
Explicit interface implemetationPrivate methodIEditableCollectionViewAddNewItem.AddNewItemAdds the specified object to the collection.
Explicit interface implemetationPrivate propertyIEditableCollectionViewAddNewItem.CanAddNewItemGets a value that indicates whether a specified object can be added to the collection.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an IEnumerator object that you can use to enumerate the items in the view. (Inherited from CollectionView.)
Explicit interface implemetationPrivate propertyIItemProperties.ItemPropertiesGets a collection that contains information about the properties that are available on the items in a collection.
Explicit interface implemetationPrivate propertyIList.IsFixedSizeThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Explicit interface implemetationPrivate propertyIList.IsReadOnlyThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Explicit interface implemetationPrivate eventINotifyCollectionChanged.CollectionChangedOccurs when the view has changed. (Inherited from CollectionView.)
Explicit interface implemetationPrivate eventINotifyPropertyChanged.PropertyChangedOccurs when a property value changes. (Inherited from CollectionView.)
Explicit interface implemetationPrivate methodIWeakEventListener.ReceiveWeakEventReceives events from the centralized event manager.
Top

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

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

Community Additions

ADD
Show:
© 2014 Microsoft