ItemCollection Class
![]() |
---|
The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience. |
Holds the list of items that constitute the content of an ItemsControl.
Assembly: PresentationFramework (in PresentationFramework.dll)
System.Windows.Threading.DispatcherObject
System.Windows.Data.CollectionView
System.Windows.Controls.ItemCollection
[<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
Name | Description | |
---|---|---|
![]() | CanChangeLiveFiltering | Gets a value that indicates whether the collection view supports turning filtering data in real time on or off. |
![]() | CanChangeLiveGrouping | Gets a value that indicates whether the collection view supports turning grouping data in real time on or off. |
![]() | CanChangeLiveSorting | Gets a value that indicates whether the collection view supports turning sorting data in real time on or off. |
![]() | CanFilter | Gets a value that indicates whether this collection view supports filtering.(Overrides CollectionView.CanFilter.) |
![]() | CanGroup | Gets a value that indicates whether this collection view supports grouping.(Overrides CollectionView.CanGroup.) |
![]() | CanSort | Gets a value that indicates whether this collection view supports sorting.(Overrides CollectionView.CanSort.) |
![]() | Comparer | Returns an object that you can use to compare items in the view.(Inherited from CollectionView.) |
![]() | Count | Gets the number of records in the collection. (Overrides CollectionView.Count.) |
![]() | Culture | Gets or sets the culture information to use during sorting.(Inherited from CollectionView.) |
![]() | CurrentItem | Gets the current item in the view.(Overrides CollectionView.CurrentItem.) |
![]() | CurrentPosition | Gets the ordinal position of the current item within the view.(Overrides CollectionView.CurrentPosition.) |
![]() | Dispatcher | Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.) |
![]() | Filter | Gets or sets a callback used to determine if an item is suitable for inclusion in the view.(Overrides CollectionView.Filter.) |
![]() | GroupDescriptions | Gets a collection of GroupDescription objects that defines how to group the items.(Overrides CollectionView.GroupDescriptions.) |
![]() | Groups | Gets the top-level groups that are constructed according to the GroupDescriptions.(Overrides CollectionView.Groups.) |
![]() | IsCurrentAfterLast | Gets a value that indicates whether the current item of the view is beyond the end of the collection.(Overrides CollectionView.IsCurrentAfterLast.) |
![]() | IsCurrentBeforeFirst | Gets a value that indicates whether the current item of the view is beyond the beginning of the collection.(Overrides CollectionView.IsCurrentBeforeFirst.) |
![]() | IsEmpty | Gets a value that indicates whether the resulting (filtered) view is empty.(Overrides CollectionView.IsEmpty.) |
![]() | IsInUse | Gets a value that indicates whether any object is subscribing to the events of this CollectionView.(Inherited from CollectionView.) |
![]() | IsLiveFiltering | Gets or sets a value that indicates whether filtering data in real time is enabled. |
![]() | IsLiveGrouping | Gets or sets a value that indicates whether grouping data in real time is enabled. |
![]() | IsLiveSorting | Gets or sets a value that indicates whether sorting in real time is enabled. |
![]() | Item(Int32) | Gets or sets the item at the given zero-based index. |
![]() | LiveFilteringProperties | Gets a collection of strings that specify the properties that participate in filtering data in real time. |
![]() | LiveGroupingProperties | Gets a collection of strings that specify the properties that participate in grouping data in real time. |
![]() | LiveSortingProperties | Gets a collection of strings that specify the properties that participate in sorting data in real time. |
![]() | NeedsRefresh | Gets a value that indicates whether the collection needs to be refreshed.(Overrides CollectionView.NeedsRefresh.) |
![]() | SortDescriptions | Gets a collection of SortDescription objects that describe how the items in the collection are sorted in the view.(Overrides CollectionView.SortDescriptions.) |
![]() | SourceCollection | Gets the unsorted and unfiltered collection that underlies this collection view. (Overrides CollectionView.SourceCollection.) |
Name | Description | |
---|---|---|
![]() | Add(Object) | Adds an item to the ItemCollection. |
![]() | CheckAccess() | Determines whether the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.) |
![]() | Clear() | Clears the collection and releases the references on all items currently in the collection. |
![]() | Contains(Object) | Returns a value that indicates whether the specified item is in this view.(Overrides CollectionView.Contains(Object).) |
![]() | CopyTo(Array, Int32) | Copies the elements of the collection to an array, starting at a particular array index. |
![]() | DeferRefresh() | Enters a defer cycle that you can use to merge changes to the view and delay automatic refresh.(Overrides CollectionView.DeferRefresh().) |
![]() | DetachFromSourceCollection() | Removes the reference to the underlying collection from the CollectionView.(Inherited from CollectionView.) |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetItemAt(Int32) | Returns the item at the specified zero-based index in this view.(Overrides CollectionView.GetItemAt(Int32).) |
![]() | GetType() | |
![]() | IndexOf(Object) | Returns the index in this collection where the specified item is located. (Overrides CollectionView.IndexOf(Object).) |
![]() | Insert(Int32, Object) | Inserts an element into the collection at the specified index. |
![]() | MoveCurrentTo(Object) | Sets the specified item in the collection as the CurrentItem.(Overrides CollectionView.MoveCurrentTo(Object).) |
![]() | MoveCurrentToFirst() | Sets the first item in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToFirst().) |
![]() | MoveCurrentToLast() | Sets the last item in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToLast().) |
![]() | MoveCurrentToNext() | Sets the item after the CurrentItem in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToNext().) |
![]() | MoveCurrentToPosition(Int32) | Sets the item at the specified index to be the CurrentItem in the view.(Overrides CollectionView.MoveCurrentToPosition(Int32).) |
![]() | MoveCurrentToPrevious() | Sets the item before the CurrentItem in the view as the CurrentItem.(Overrides CollectionView.MoveCurrentToPrevious().) |
![]() | PassesFilter(Object) | Returns a value that indicates whether the specified item belongs to this view.(Overrides CollectionView.PassesFilter(Object).) |
![]() | Refresh() | Re-creates the view.(Inherited from CollectionView.) |
![]() | Remove(Object) | Removes the specified item reference from the collection or view. |
![]() | RemoveAt(Int32) | Removes the item at the specified index of the collection or view. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
![]() | VerifyAccess() | Enforces that the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.) |
Name | Description | |
---|---|---|
![]() | CurrentChanged | Occurs after the CurrentItem has changed.(Inherited from CollectionView.) |
![]() | CurrentChanging | Occurs when the CurrentItem is changing.(Inherited from CollectionView.) |
Name | Description | |
---|---|---|
![]() ![]() | INotifyCollectionChanged.CollectionChanged | Occurs when the view has changed.(Inherited from CollectionView.) |
![]() ![]() | INotifyPropertyChanged.PropertyChanged | Occurs when a property value changes.(Inherited from CollectionView.) |
![]() ![]() | IEnumerable.GetEnumerator() | Returns an IEnumerator object that you can use to enumerate the items in the view.(Inherited from CollectionView.) |
![]() ![]() | IEditableCollectionView.AddNew() | Adds a new item to the collection. |
![]() ![]() | IEditableCollectionView.CancelEdit() | Ends the edit transaction and, if possible, restores the original value to the item. |
![]() ![]() | IEditableCollectionView.CancelNew() | Ends the add transaction and discards the pending new item. |
![]() ![]() | IEditableCollectionView.CommitEdit() | Ends the edit transaction and saves the pending changes. |
![]() ![]() | IEditableCollectionView.CommitNew() | Ends the add transaction and saves the pending new item. |
![]() ![]() | IEditableCollectionView.EditItem(Object) | Begins an edit transaction of the specified item. |
![]() ![]() | IEditableCollectionView.Remove(Object) | Removes the specified item from the collection. |
![]() ![]() | IEditableCollectionView.RemoveAt(Int32) | Removes the item at the specified position from the collection. |
![]() ![]() | IEditableCollectionViewAddNewItem.AddNewItem(Object) | Adds the specified object to the collection. |
![]() ![]() | IWeakEventListener.ReceiveWeakEvent(Type, Object, EventArgs) | Receives events from the centralized event manager. |
![]() ![]() | ICollection.IsSynchronized | This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. |
![]() ![]() | ICollection.SyncRoot | This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. |
![]() ![]() | IList.IsFixedSize | This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. |
![]() ![]() | IList.IsReadOnly | This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. |
![]() ![]() | IEditableCollectionView.CanAddNew | Gets a value that indicates whether a new item can be added to the collection. |
![]() ![]() | IEditableCollectionView.CanCancelEdit | Gets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object. |
![]() ![]() | IEditableCollectionView.CanRemove | Gets a value that indicates whether an item can be removed from the collection. |
![]() ![]() | IEditableCollectionView.CurrentAddItem | Gets the item that is being added during the current add transaction. |
![]() ![]() | IEditableCollectionView.CurrentEditItem | Gets the item in the collection that is being edited. |
![]() ![]() | IEditableCollectionView.IsAddingNew | Gets a value that indicates whether an add transaction is in progress. |
![]() ![]() | IEditableCollectionView.IsEditingItem | Gets a value that indicates whether an edit transaction is in progress. |
![]() ![]() | IEditableCollectionView.NewItemPlaceholderPosition | Gets or sets the position of the new item placeholder in the collection view. |
![]() ![]() | IEditableCollectionViewAddNewItem.CanAddNewItem | Gets a value that indicates whether a specified object can be added to the collection. |
![]() ![]() | IItemProperties.ItemProperties | Gets a collection that contains information about the properties that are available on the items in a collection. |
Name | Description | |
---|---|---|
![]() | AsParallel() | Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.) |
![]() | AsQueryable() | Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.) |
![]() | Cast<'TResult>() | Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.) |
![]() | OfType<'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.
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:
Alternately, you can specify filtering, sorting, and grouping criteria in XAML using CollectionViewSource.
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.