Udostępnij za pośrednictwem


UIElementCollection Class

Definition

Represents an ordered collection of UIElement objects.

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)]
class UIElementCollection final : IIterable<UIElement>, IVector<UIElement>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class UIElementCollection final : 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)]
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)]
public sealed class UIElementCollection : IEnumerable<UIElement>, IList<UIElement>
Public NotInheritable Class UIElementCollection
Implements IEnumerable(Of UIElement), IList(Of UIElement)
<panelobject>
  oneOrMoreChildren
</panelobject>
Inheritance
Object Platform::Object IInspectable UIElementCollection
Attributes
Implements

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

Properties

Size

Gets the size (count) of the collection.

Methods

Append(UIElement)

Adds a new item to the collection.

Clear()

Removes all items from the collection.

First()

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

GetAt(UInt32)

Returns the item located at the specified index.

GetMany(UInt32, UIElement[])

Retrieves multiple elements in a single pass through the iterator.

GetView()

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.

RemoveAt(UInt32)

Removes the item at the specified index.

RemoveAtEnd()

Removes the last item in the collection.

ReplaceAll(UIElement[])

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