UIElementCollection Class

Definition

Represents an ordered collection of UIElement objects.

Equivalent WinUI class: Microsoft.UI.Xaml.Controls.UIElementCollection.

public ref class UIElementCollection sealed : IIterable<UIElement ^>, IVector<UIElement ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class UIElementCollection sealed : IIterable<UIElement>, IVector<UIElement>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class UIElementCollection sealed : IIterable<UIElement>, IVector<UIElement>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
public sealed class UIElementCollection : IEnumerable<UIElement>, IList<UIElement>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.WebHostHidden]
public sealed class UIElementCollection : IEnumerable<UIElement>, IList<UIElement>
Public NotInheritable Class UIElementCollection
Implements IEnumerable(Of UIElement), IList(Of UIElement)
<panelobject>
  oneOrMoreChildren
</panelobject>
Inheritance
UIElementCollection
Attributes
Implements

Windows 10 requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

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.

Properties

Size

Gets the size (count) of the collection.

Equivalent WinUI property: Microsoft.UI.Xaml.Controls.UIElementCollection.Size.

Methods

Append(UIElement)

Adds a new item to the collection.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.Append.

Clear()

Removes all items from the collection.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.Clear.

First()

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

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.First.

GetAt(UInt32)

Returns the item located at the specified index.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.GetAt.

GetMany(UInt32, UIElement[])

Retrieves multiple elements in a single pass through the iterator.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.GetMany.

GetView()

Gets an immutable view into the collection.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.GetView.

IndexOf(UIElement, UInt32)

Retrieves the index of the specified item.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.IndexOf.

InsertAt(UInt32, UIElement)

Inserts the specified item at the specified index.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.InsertAt.

Move(UInt32, UInt32)

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

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.Move.

RemoveAt(UInt32)

Removes the item at the specified index.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.RemoveAt.

RemoveAtEnd()

Removes the last item in the collection.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.RemoveAtEnd.

ReplaceAll(UIElement[])

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

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.ReplaceAll.

SetAt(UInt32, UIElement)

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

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.SetAt.

Applies to

See also