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 是从 Panel 的 Children 属性获取的对象类型。 例如,如果从 Grid.Children 获取值,则该值为 UIElementCollection 实例。 在 Windows 运行时 API 中使用 UIElementCollection 的所有属性都是只读属性,其中属性在首次实例化对象时使用零项初始化。 但是,可以使用 UIElementCollection 属性和方法在运行时在集合中添加、删除或查询项。
UIElementCollection 中的项的类型被约束为 UIElement。 但 UIElement 是使用 XAML Windows 运行时的基元素类,因此有数百种元素类型可以视为 UIElement,因此可以是 UIElementCollection 中的项之一。
枚举 C 中的集合#
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 值。 |
适用于
另请参阅
- Children
- VisualTreeHelper
- UIElement
IVector IIterable IList