UIElementCollection Class


Represents an ordered collection of UIElement objects.

public ref class UIElementCollection sealed : IIterable<UIElement ^>, IVector<UIElement ^>
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class UIElementCollection final : IIterable<UIElement>, IVector<UIElement>
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
public sealed class UIElementCollection : IEnumerable<UIElement>, IList<UIElement>
Public NotInheritable Class UIElementCollection
Implements IEnumerable(Of UIElement), IList(Of UIElement)
Windows.Foundation.Metadata.ContractVersionAttribute Windows.Foundation.Metadata.MarshalingBehaviorAttribute Windows.Foundation.Metadata.WebHostHiddenAttribute


A UIElementCollection is the type of object that you get from the Children property of a Panel. For example, if you get a value from Grid.Children, that value is a UIElementCollection instance. All the properties that use a UIElementCollection in the Windows Runtime API are read-only properties, where the property is initialized with zero items when an object is first instantiated. But you can then add, remove or query items in the collection at run time, using the UIElementCollection properties and methods.

The type of the items in the UIElementCollection is constrained as UIElement. But UIElement is a base element class in Windows Runtime using XAML, so there are hundreds of element types that can be treated as a UIElement and can thus be one of the items in a UIElementCollection.

Enumerating the collection in C# or Microsoft Visual Basic

A UIElementCollection is enumerable, so you can use language-specific syntax such as foreach in C# to enumerate the items in the UIElementCollection. The compiler does the type-casting for you and you won't need to cast to IEnumerable<UIElement> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable with a UIElement constraint.



Gets the size (count) of the collection.



Adds a new item to the collection.


Removes all items from the collection.


Returns the iterator object that can iterate over the items in the UIElementCollection.


Returns the item located at the specified index.

GetMany(UInt32, UIElement[])

Retrieves multiple elements in a single pass through the iterator.


Gets an immutable view into the collection.

IndexOf(UIElement, UInt32)

Retrieves the index of the specified item.

InsertAt(UInt32, UIElement)

Inserts the specified item at the specified index.

Move(UInt32, UInt32)

Moves the item at the specified index to a new location in the collection.


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.

SetAt(UInt32, UIElement)

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

Applies to

See also