UIElementCollection 類別

定義

表示 UIElement 物件的已排序集合。

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>
繼承
Object Platform::Object IInspectable UIElementCollection
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

備註

UIElementCollection 是從 PanelChildren 屬性取得的物件類型。 例如,如果您從 Grid.Children 取得值,該值就是 UIElementCollection 實例。 Windows 執行階段 API 中使用 UIElementCollection 的所有屬性都是只讀屬性,其中當物件第一次具現化時,屬性會以零個專案初始化。 但是,您可以使用 UIElementCollection 屬性和方法,在運行時間新增、移除或查詢集合中的專案。

UIElementCollection 中的項目類型會限制為 UIElement。 但UIElement是使用 XAML Windows 執行階段 的基底元素類別,因此有數百個元素類型可以視為UIElement,因此可以是UIElementCollection中的其中一個專案。

列舉 C# 或 Microsoft Visual Basic 中的集合

UIElementCollection 是可列舉的,因此您可以使用 C# 中的 foreach 之類的語言特定語法來列舉 UIElementCollection 中的專案。 編譯程式會為您執行型別轉換,而且您不需要明確地轉換成 IEnumerable<UIElement> 。 如果您需要明確轉換,例如,如果您想要呼叫 GetEnumerator,請使用 UIElement 條件約束轉換成 IEnumerable<T>

屬性

Size

取得集合的大小 (計數) 。

方法

Append(UIElement)

將新項目加入至集合中。

Clear()

移除集合的所有項目。

First()

傳回反覆運算器物件,可逐一查看 UIElementCollection中的專案。

GetAt(UInt32)

傳回位於指定索引處的專案。

GetMany(UInt32, UIElement[])

擷取單一傳遞反覆運算器中的多個元素。

GetView()

取得集合中的不可變檢視。

IndexOf(UIElement, UInt32)

擷取指定專案的索引。

InsertAt(UInt32, UIElement)

在指定的索引處插入指定的專案。

Move(UInt32, UInt32)

將所指定索引位置的項目移至集合中的新位置。

RemoveAt(UInt32)

移除指定之索引處的項目。

RemoveAtEnd()

拿掉集合中的最後一個專案。

ReplaceAll(UIElement[])

一開始清除集合,然後將提供的數位插入為新專案。

SetAt(UInt32, UIElement)

將位於指定索引處的值設定為指定的 UIElement 值。

適用於

另請參閱