UIElementCollection UIElementCollection UIElementCollection UIElementCollection Class

定义

表示 UIElement 子元素的有序集合。Represents an ordered collection of UIElement child elements.

public ref class UIElementCollection : System::Collections::IList
public class UIElementCollection : System.Collections.IList
type UIElementCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class UIElementCollection
Implements IList
继承
UIElementCollectionUIElementCollectionUIElementCollectionUIElementCollection
实现

示例

下面的示例使用Add方法将子内容添加到父级。 StackPanelThe following example uses the Add method to add child content to a parent StackPanel. 可以通过使用Children类型UIElementCollection为的属性来执行此操作。You do this by using the Children property, which is of type UIElementCollection.

void AddButton(object sender, MouseButtonEventArgs e)
{
	sp1.Children.Clear();
	btn = new Button();
	btn.Content = "New Button";
	sp1.Children.Add(btn);
}

注解

Panel 基类UIElementCollection使用来表示其子元素的集合。The Panel base class uses a UIElementCollection to represent its collection of child elements. 定义UIElementCollection的方法和属性会影响派生自Panel的所有对象, 并定义公共功能Panel集以便对子元素进行操作。Methods and properties defined by the UIElementCollection affect all objects derived from Panel and define a common feature-set for the manipulation of Panel child elements.

UIElementCollection与自身的上下文 (类) 关联。A UIElementCollection has affinity to its own context (class). 必须从拥有Panel的上下文访问集合。You must access the collection from the context of the owning Panel.

构造函数

UIElementCollection(UIElement, FrameworkElement) UIElementCollection(UIElement, FrameworkElement) UIElementCollection(UIElement, FrameworkElement) UIElementCollection(UIElement, FrameworkElement)

初始化 UIElementCollection 类的新实例。Initializes a new instance of the UIElementCollection class.

属性

Capacity Capacity Capacity Capacity

获取或设置 UIElementCollection 可包含的元素数。Gets or sets the number of elements that the UIElementCollection can contain.

Count Count Count Count

获取集合中元素的实际数目。Gets the actual number of elements in the collection.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

获取一个值,该值指示是否同步对 ICollection 接口的访问(线程安全)。Gets a value that indicates whether access to the ICollection interface is synchronized (thread-safe).

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

获取或设置存储在 UIElement 的从零开始的索引位置的 UIElementCollectionGets or sets the UIElement stored at the zero-based index position of the UIElementCollection.

SyncRoot SyncRoot SyncRoot SyncRoot

获取一个对象,该对象可用于同步对 ICollection 接口的访问。Gets an object that you can use to synchronize access to the ICollection interface.

方法

Add(UIElement) Add(UIElement) Add(UIElement) Add(UIElement)

将指定的元素添加到 UIElementCollection 中。Adds the specified element to the UIElementCollection.

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

UIElementCollection 中移除所有元素。Removes all elements from a UIElementCollection.

ClearLogicalParent(UIElement) ClearLogicalParent(UIElement) ClearLogicalParent(UIElement) ClearLogicalParent(UIElement)

当元素离开 UIElementCollection 时,清除此元素的逻辑父级。Clears the logical parent of an element when the element leaves a UIElementCollection.

Contains(UIElement) Contains(UIElement) Contains(UIElement) Contains(UIElement)

确定指定的元素是否在 UIElementCollection 中。Determines whether a specified element is in the UIElementCollection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

从指定的索引位置开始,将 UIElementUIElementCollection 复制到数组。Copies a UIElement from a UIElementCollection to an array, starting at a specified index position.

CopyTo(UIElement[], Int32) CopyTo(UIElement[], Int32) CopyTo(UIElement[], Int32) CopyTo(UIElement[], Int32)

从指定的索引位置开始,将 UIElementUIElementCollection 复制到数组。Copies a UIElement from a UIElementCollection to an array, starting at a specified index position.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回可循环访问 UIElementCollection 的枚举器。Returns an enumerator that can iterate the UIElementCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(UIElement) IndexOf(UIElement) IndexOf(UIElement) IndexOf(UIElement)

返回 UIElementCollection 中指定元素的索引位置。Returns the index position of a specified element in a UIElementCollection.

Insert(Int32, UIElement) Insert(Int32, UIElement) Insert(Int32, UIElement) Insert(Int32, UIElement)

将元素插入到位于指定索引位置的 UIElementCollection 中。Inserts an element into a UIElementCollection at the specified index position.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(UIElement) Remove(UIElement) Remove(UIElement) Remove(UIElement)

UIElementCollection 中移除指定元素。Removes the specified element from a UIElementCollection.

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

移除位于指定索引处的 UIElementRemoves the UIElement at the specified index.

RemoveRange(Int32, Int32) RemoveRange(Int32, Int32) RemoveRange(Int32, Int32) RemoveRange(Int32, Int32)

UIElementCollection 中移除一系列元素。Removes a range of elements from a UIElementCollection.

SetLogicalParent(UIElement) SetLogicalParent(UIElement) SetLogicalParent(UIElement) SetLogicalParent(UIElement)

设置 UIElementCollection 中的元素的逻辑父级。Sets the logical parent of an element in a UIElementCollection.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 Add(Object)For a description of this member, see Add(Object).

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 Contains(Object)For a description of this member, see Contains(Object).

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 IndexOf(Object)For a description of this member, see IndexOf(Object).

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 Insert(Int32, Object)For a description of this member, see Insert(Int32, Object).

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 IsFixedSizeFor a description of this member, see IsFixedSize.

IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 IsReadOnlyFor a description of this member, see IsReadOnly.

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 Item[Int32]For a description of this member, see Item[Int32].

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

此类型或成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不可直接在代码中使用。This type or member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 Remove(Object)For a description of this member, see Remove(Object).

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅