ItemCollection ItemCollection ItemCollection ItemCollection Class

Definition

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

public : sealed class ItemCollection : IIterable<Platform::Object>, IObservableVector<Platform::Object>, IVector<Platform::Object>
struct winrt::Windows::UI::Xaml::Controls::ItemCollection : IIterable<Platform::Object>, IObservableVector<Platform::Object>, IVector<Platform::Object>
public sealed class ItemCollection : IEnumerable<Object>, IObservableVector<Object>, IList<Object>
Public NotInheritable Class ItemCollection Implements IEnumerable<Object>, IObservableVector<Object>, IList<Object>
<ItemsControl>
  oneOrMoreFrameworkElements
</ItemsControl>
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 IEnumerablewith an Object or FrameworkElement constraint.

Properties

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Gets or sets the element at the specified index.

// This member is not implemented in C++/CX
T this[int index] { get; set; }
Property Item(index As Integer) As T
T this[int index] { get; set; }
Parameters
index

The zero-based index of the element to get or set.

Value
T T T T

The element at the specified index.

Exceptions

index is not a valid index in the System.Collections.Generic.IList`1.

The property is set and the System.Collections.Generic.IList`1 is read-only.

Size Size Size Size

Gets the size (count) of the collection.

public : unsigned int Size { get; }
uint32_t Size();
// This member is not implemented in C#
' This member is not implemented in VB.Net
Value
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(Platform::Object value)
void Append(winrt::Windows::Foundation::IInspectable value) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
value
Object Object

The new item to add.

Clear() Clear() Clear() Clear()

Removes all items from the collection.

public : void Clear()
void Clear() const;
// This member is not implemented in C#
' This member is not implemented in VB.Net

First() First() First() First()

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

public : IIterator<Platform::Object> First()
IIterator<winrt::Windows::Foundation::IInspectable> First() const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
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 : Platform::Object GetAt(unsigned int index)
winrt::Windows::Foundation::IInspectable GetAt(uint32_t index) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
index
UInt32 UInt32

The integer index for the value to retrieve.

Returns
object object

The item value at the specified index.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through the collection.

// This member is not implemented in C++/CX
IEnumerator<T> GetEnumerator()
Function GetEnumerator As IEnumerator(Of T)
IEnumerator<T> GetEnumerator()
Returns

An enumerator that can be used to iterate through the collection.

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

Retrieves multiple elements in a single pass through the iterator.

public : unsigned int GetMany(unsigned int startIndex, Platform::Object[] items)
uint32_t GetMany(uint32_t startIndex, winrt::Windows::Foundation::IInspectable[] items) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
startIndex
UInt32 UInt32

The index from which to start retrieval.

items
Object[] 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

The number of items retrieved.

GetView() GetView() GetView() GetView()

Gets an immutable view into the collection.

public : IVectorView<Platform::Object> GetView()
IVectorView<winrt::Windows::Foundation::IInspectable> GetView() const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Returns
IReadOnlyList<object> IReadOnlyList<object>

An object representing the immutable collection view.

IndexOf(T) IndexOf(T) IndexOf(T) IndexOf(T)

Determines the index of a specific item in the System.Collections.Generic.IList`1.

// This member is not implemented in C++/CX
int IndexOf(T item)
Function IndexOf(item As T) As Integer
int IndexOf(T item)
Parameters
item
T T T T

The object to locate in the System.Collections.Generic.IList`1.

Returns

The index of item if found in the list; otherwise, -1.

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

Retrieves the index of the specified item.

public : Platform::Boolean IndexOf(Platform::Object value, unsigned int index)
bool IndexOf(winrt::Windows::Foundation::IInspectable value, uint32_t index) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
value
Object Object

The value to find in the collection.

index
UInt32 UInt32

The index of the item, if it is found.

Returns
bool bool

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

Insert(Int32, T) Insert(Int32, T) Insert(Int32, T) Insert(Int32, T)

Inserts an item to the System.Collections.Generic.IList`1 at the specified index.

// This member is not implemented in C++/CX
void Insert(int index, T item)
Sub Insert(index As Integer, item As T)
void Insert(int index, T item)
Parameters
index

The zero-based index at which item should be inserted.

item
T T T T

The object to insert into the System.Collections.Generic.IList`1.

Exceptions

index is not a valid index in the System.Collections.Generic.IList`1.

The System.Collections.Generic.IList`1 is read-only.

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

Inserts the specified item at the specified index.

public : void InsertAt(unsigned int index, Platform::Object value)
void InsertAt(uint32_t index, winrt::Windows::Foundation::IInspectable value) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
index
UInt32 UInt32

The index at which to set the value.

value
Object Object

The value to set.

Remarks

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

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Removes the System.Collections.Generic.IList`1 item at the specified index.

// This member is not implemented in C++/CX
void RemoveAt(int index)
Sub RemoveAt(index As Integer)
void RemoveAt(int index)
Parameters
index

The zero-based index of the item to remove.

Exceptions

index is not a valid index in the System.Collections.Generic.IList`1.

The System.Collections.Generic.IList`1 is read-only.

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

Removes the item at the specified index.

public : void RemoveAt(unsigned int index)
void RemoveAt(uint32_t index) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
index
UInt32 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()
void RemoveAtEnd() const;
// This member is not implemented in C#
' This member is not implemented in VB.Net

ReplaceAll(Object[]) ReplaceAll(Object[]) ReplaceAll(Object[]) ReplaceAll(Object[])

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

public : void ReplaceAll(Platform::Object[] items)
void ReplaceAll(winrt::Windows::Foundation::IInspectable[] items) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
items
Object[] 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(unsigned int index, Platform::Object value)
void SetAt(uint32_t index, winrt::Windows::Foundation::IInspectable value) const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
Parameters
index
UInt32 UInt32

The index at which to set the value.

value
Object 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 VectorChanged<Platform::Object>
// Register
event_token VectorChanged(VectorChangedEventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void VectorChanged(event_token const& cookie) const;

// Revoke with event_revoker
VectorChanged_revoker VectorChanged(auto_revoker_t, VectorChangedEventHandler<Platform::Object> const& handler) const;
public event VectorChangedEventHandler VectorChanged<object>
Public Event VectorChangedEventHandler VectorChanged( Of ( Of object ))

See Also