UIElementCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
public ref class UIElementCollection sealed : IIterable<UIElement ^>, IVector<UIElement ^>
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class UIElementCollection final : IIterable<UIElement>, IVector<UIElement>
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 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>
- 繼承
- 屬性
- 實作
備註
UIElementCollection 是從面板的 Children 屬性中取得的物件類型。 舉例來說,如果你從 Grid.Children 取得一個值,那個值就是 UIElementCollection 實例。 所有在 Windows 執行階段 API 中使用 UIElementCollection 的屬性都是唯讀屬性,當物件首次實例化時,屬性初始化為零項目。 但你可以在執行時使用 UIElementCollection 的屬性和方法,新增、移除或查詢集合中的項目。
UIElementCollection 中項目的類型被限制為 UIElement。 但 UIElement 是使用 XAML 在 Windows 執行階段 中的基底元素類別,因此有數百種元素類型可以被視為 UIElement,因此可以作為 UIElementCollection 中的一個項目。
以 C 語言列舉集合#
UIElementCollection 是可枚舉的,因此你可以使用語言特定的語法,例如 C# 中的 foreach ,來枚舉 UIElementCollection 中的項目。 編譯器會幫你做型別,你不需要明確地做 cast IEnumerable<UIElement> 。 如果你需要明確地投射,例如你想呼叫 GetEnumerator,就用 UIElement 約束投射到 IEnumerable<T>。
屬性
| 名稱 | Description |
|---|---|
| Size |
取得集合的大小(數量)。 |
方法
| 名稱 | Description |
|---|---|
| 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 值。 |
適用於
另請參閱
- Children
- VisualTreeHelper
- UIElement
IVector - 我可怕的!T>
- 伊利茲&;T>