ItemCollection ItemCollection ItemCollection Class

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

Syntax

Declaration

public sealed class ItemCollectionpublic sealed class ItemCollectionPublic NotInheritable Class ItemCollection
<ItemsControl>
  oneOrMoreFrameworkElements
</ItemsControl>

Remarks

Enumerating the collection in C# or Microsoft Visual Basic

An ItemCollection is enumerable, so you can use language-specific syntax such as foreach in C# to enumerate the items in the collection. The compiler does the type-casting for you and you won't need to cast to IEnumerable explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable<T> with an Object or FrameworkElement constraint.

Properties summary

Gets the size (count) of the collection.

Methods summary

Adds a new item to the collection.

Removes all items from the collection.

Returns the iterator for iteration over the items in the collection.

Returns the item located at the specified index.

Retrieves multiple elements in a single pass through the iterator.

Gets an immutable view into the collection.

Retrieves the index of the specified item.

Inserts the specified item at the specified index.

Removes the item at the specified index.

Removes the last item in the collection.

Initially clears the collection, then inserts the provided array as new items.

Sets the value at the specified index to the item value specified.

Events summary

Occurs when the items list of the collection has changed, or the collection is reset.

Properties

  • Size
    Size
    Size
    Size

    Gets the size (count) of the collection.

    public uint Size { get; }public uint Size { get; }Public ReadOnly Property Size As uintpublic uint Size { get; }

    Property Value

    • uint
      uint
      uint

      The count of items in the collection.

Methods

  • Append(Object)
    Append(Object)
    Append(Object)
    Append(Object)

    Adds a new item to the collection.

    public void Append(Object value)public void Append(Object value)Public Function Append(value As Object) As voidpublic void Append(Object value)

    Parameters

    • value
      System.Object
      System.Object
      System.Object

      The new item to add.

  • Clear()
    Clear()
    Clear()
    Clear()

    Removes all items from the collection.

    public void Clear()public void Clear()Public Function Clear() As voidpublic void Clear()
  • First()
    First()
    First()
    First()

    Returns the iterator for iteration over the items in the collection.

    public IIterator<object> First()public IIterator<object> First()Public Function First() As IIterator( Of object )public IIterator<object> First()

    Returns

    • The iterator object. The iterator's current position is at the 0-index position, or at the collection end if the collection is empty.

  • GetAt(UInt32)
    GetAt(UInt32)
    GetAt(UInt32)
    GetAt(UInt32)

    Returns the item located at the specified index.

    public object GetAt(UInt32 index)public object GetAt(UInt32 index)Public Function GetAt(index As UInt32) As objectpublic object GetAt(UInt32 index)

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The integer index for the value to retrieve.

    Returns

    • object
      object
      object

      The item value at the specified index.

  • GetMany(UInt32, Object[])
    GetMany(UInt32, Object[])
    GetMany(UInt32, Object[])
    GetMany(UInt32, Object[])

    Retrieves multiple elements in a single pass through the iterator.

    public uint GetMany(UInt32 startIndex, Object[] items)public uint GetMany(UInt32 startIndex, Object[] items)Public Function GetMany(startIndex As UInt32, items As Object[]) As uintpublic uint GetMany(UInt32 startIndex, Object[] items)

    Parameters

    • startIndex
      System.UInt32
      System.UInt32
      System.UInt32

      The index from which to start retrieval.

    • items
      System.Object[]
      System.Object[]
      System.Object[]

      Provides the destination for the result. Size the initial array size as a "capacity" in order to specify how many results should be retrieved.

    Returns

    • uint
      uint
      uint

      The number of items retrieved.

  • GetView()
    GetView()
    GetView()
    GetView()

    Gets an immutable view into the collection.

    public IVectorView<object> GetView()public IVectorView<object> GetView()Public Function GetView() As IVectorView( Of object )public IVectorView<object> GetView()

    Returns

    • An object representing the immutable collection view.

  • IndexOf(Object, UInt32)
    IndexOf(Object, UInt32)
    IndexOf(Object, UInt32)
    IndexOf(Object, UInt32)

    Retrieves the index of the specified item.

    public bool IndexOf(Object value, UInt32 index)public bool IndexOf(Object value, UInt32 index)Public Function IndexOf(value As Object, index As UInt32) As boolpublic bool IndexOf(Object value, UInt32 index)

    Parameters

    • value
      System.Object
      System.Object
      System.Object

      The value to find in the collection.

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The index of the item, if it is found.

    Returns

    • bool
      bool
      bool

      true if an item with the specified value was found; otherwise, false.

  • InsertAt(UInt32, Object)
    InsertAt(UInt32, Object)
    InsertAt(UInt32, Object)
    InsertAt(UInt32, Object)

    Inserts the specified item at the specified index.

    public void InsertAt(UInt32 index, Object value)public void InsertAt(UInt32 index, Object value)Public Function InsertAt(index As UInt32, value As Object) As voidpublic void InsertAt(UInt32 index, Object value)

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The index at which to set the value.

    • value
      System.Object
      System.Object
      System.Object

      The value to set.

    Remarks

    InsertAt expands the collection and moves all subsequent index items by one.

  • RemoveAt(UInt32)
    RemoveAt(UInt32)
    RemoveAt(UInt32)
    RemoveAt(UInt32)

    Removes the item at the specified index.

    public void RemoveAt(UInt32 index)public void RemoveAt(UInt32 index)Public Function RemoveAt(index As UInt32) As voidpublic void RemoveAt(UInt32 index)

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The index position of the item to remove.

    Remarks

    If successful, calling this method reduces the collection size by one. Items with index values greater than the called index have their index values reduced by one.

  • RemoveAtEnd()
    RemoveAtEnd()
    RemoveAtEnd()
    RemoveAtEnd()

    Removes the last item in the collection.

    public void RemoveAtEnd()public void RemoveAtEnd()Public Function RemoveAtEnd() As voidpublic void RemoveAtEnd()
  • ReplaceAll(Object[])
    ReplaceAll(Object[])
    ReplaceAll(Object[])
    ReplaceAll(Object[])

    Initially clears the collection, then inserts the provided array as new items.

    public void ReplaceAll(Object[] items)public void ReplaceAll(Object[] items)Public Function ReplaceAll(items As Object[]) As voidpublic void ReplaceAll(Object[] items)

    Parameters

    • items
      System.Object[]
      System.Object[]
      System.Object[]

      The new collection items.

    Remarks

    For implementations that track a "changed" event, the initial reset fires an event, but the items added don't fire discrete per-item events.

  • SetAt(UInt32, Object)
    SetAt(UInt32, Object)
    SetAt(UInt32, Object)
    SetAt(UInt32, Object)

    Sets the value at the specified index to the item value specified.

    public void SetAt(UInt32 index, Object value)public void SetAt(UInt32 index, Object value)Public Function SetAt(index As UInt32, value As Object) As voidpublic void SetAt(UInt32 index, Object value)

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The index at which to set the value.

    • value
      System.Object
      System.Object
      System.Object

      The value to set.

    Remarks

    SetAt replaces the item at the index, and the collection count remains the same.

Events

  • VectorChanged
    VectorChanged
    VectorChanged
    VectorChanged

    Occurs when the items list of the collection has changed, or the collection is reset.

    public event VectorChangedEventHandler VectorChangedpublic event VectorChangedEventHandler VectorChangedPublic Event VectorChangedpublic event VectorChangedEventHandler VectorChanged

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.Controls.dll