Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
[LocalizabilityAttribute(LocalizationCategory.Ignore)] public sealed class ItemCollection : CollectionView, IList, ICollection, IEnumerable, IWeakEventListener
/** @attribute LocalizabilityAttribute(LocalizationCategory.Ignore) */ public final class ItemCollection extends CollectionView implements IList, ICollection, IEnumerable, IWeakEventListener
LocalizabilityAttribute(LocalizationCategory.Ignore) public final class ItemCollection extends CollectionView implements IList, ICollection, IEnumerable, IWeakEventListener
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.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.