UIElementCollection UIElementCollection UIElementCollection UIElementCollection Class

Definition

Represents an ordered collection of UIElement objects.

public : sealed class UIElementCollection : IIterable<UIElement>, IVector<UIElement>, IUIElementCollection
struct winrt::Windows::UI::Xaml::Controls::UIElementCollection : IIterable<UIElement>, IVector<UIElement>, IUIElementCollection
public sealed class UIElementCollection : IEnumerable<UIElement>, IList<UIElement>, IUIElementCollection
Public NotInheritable Class UIElementCollection Implements IEnumerable<UIElement>, IList<UIElement>, IUIElementCollection
<panelobject>
  oneOrMoreChildren
</panelobject>
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

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

Gets or sets the element at the specified index.

Size Size Size Size

Gets the size (count) of the collection.

Methods

Append(UIElement) Append(UIElement) Append(UIElement) Append(UIElement)

Adds a new item to the collection.

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

Removes all items from the collection.

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

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

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

Returns the item located at the specified index.

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

Returns an enumerator that iterates through the collection.

GetMany(UInt32, UIElement[]) GetMany(UInt32, UIElement[]) GetMany(UInt32, UIElement[]) GetMany(UInt32, UIElement[])

Retrieves multiple elements in a single pass through the iterator.

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

Gets an immutable view into the collection.

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

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

IndexOf(UIElement, UInt32) IndexOf(UIElement, UInt32) IndexOf(UIElement, UInt32) IndexOf(UIElement, UInt32)

Retrieves the index of the specified item.

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.

InsertAt(UInt32, UIElement) InsertAt(UInt32, UIElement) InsertAt(UInt32, UIElement) InsertAt(UInt32, UIElement)

Inserts the specified item at the specified index.

Move(UInt32, UInt32) Move(UInt32, UInt32) Move(UInt32, UInt32) Move(UInt32, UInt32)

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

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

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

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

Removes the item at the specified index.

RemoveAtEnd() RemoveAtEnd() RemoveAtEnd() RemoveAtEnd()

Removes the last item in the collection.

ReplaceAll(UIElement[]) ReplaceAll(UIElement[]) ReplaceAll(UIElement[]) ReplaceAll(UIElement[])

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

SetAt(UInt32, UIElement) SetAt(UInt32, UIElement) SetAt(UInt32, UIElement) SetAt(UInt32, UIElement)

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

See also