Windows Dev Center

UIElementCollection class

Represents an ordered collection of UIElement objects.




public sealed class UIElementCollection : IList<UIElement>,


XAML Values


One or more objects elements for classes that derive from UIElement.


Object element (opening and closing tags) for a class that derives from Panel. Typically this is one of the panels, such as Canvas, Grid, or StackPanel.


The UIElementCollection class has these types of members:


The UIElementCollection class has these methods. It also inherits methods from the Object class.

Add [C#, VB]Adds a new item to the end of the collection. The item you add must be a UIElement derived element.
Append [C++]Adds a new item to the collection.
Clear Removes all items from the collection.
Contains [C#, VB]Determines whether an element is in the collection.
CopyTo [C#, VB]Copies the elements of the collection to an array, starting at a particular array index in the destination array.
First [C++]Returns the iterator object that can iterate over the items in the UIElementCollection.
GetAt [C++]Returns the item located at the specified index.
GetMany [C++]Retrieves multiple elements in a single pass through the iterator.
GetView [C++]Gets an immutable view into the collection.
IndexOf [C++]Retrieves the index of the specified item.
IndexOf [C#, VB]Determines the index of a specific item in the collection.
Insert [C#, VB]Inserts an item into the collection at the specified index.
InsertAt [C++]Inserts the specified item at the specified index.
Move Moves the item at the specified index to a new location in the collection.
Remove [C#, VB]Removes a specific object from the collection.
RemoveAt [C++]Removes the item at the specified index.
RemoveAt [C#, VB]Removes the element at the specified index of the collection.
RemoveAtEnd [C++]Removes the last item in the collection.
ReplaceAll [C++]Initially clears the collection, then inserts the provided array as new items.
SetAt [C++]Sets the value at the specified index to the UIElement value specified.



The UIElementCollection class has these properties.

PropertyAccess typeDescription

Count [C#, VB]

Read-onlyGets the number of elements that are contained in the collection.

IsReadOnly [C#, VB]

Read-onlyGets a value indicating whether the collection is read-only.

Item [C#, VB]

Read/writeGets or sets the element at the specified index.

Size [C++]

Read-onlyGets the size (count) of the collection.



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<T> with a UIElement constraint.

Requirements (Windows 10 device family)

Device family


API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml::Controls [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml::Controls [C++]





See also




© 2015 Microsoft