Skip to main content
.NET Framework Class Library
UIElementCollection Class

Represents an ordered collection of UIElement child elements.

Inheritance Hierarchy
SystemObject
  System.Windows.ControlsUIElementCollection

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
Syntax
Public Class UIElementCollection _
	Implements [%$TOPIC/ms617847_en-us_VS_110_3_0_0_0_0%], [%$TOPIC/ms617847_en-us_VS_110_3_0_0_0_1%], [%$TOPIC/ms617847_en-us_VS_110_3_0_0_0_2%]
public class UIElementCollection : [%$TOPIC/ms617847_en-us_VS_110_3_0_1_0_0%], 
	[%$TOPIC/ms617847_en-us_VS_110_3_0_1_0_1%], [%$TOPIC/ms617847_en-us_VS_110_3_0_1_0_2%]
public ref class UIElementCollection : [%$TOPIC/ms617847_en-us_VS_110_3_0_2_0_0%], 
	[%$TOPIC/ms617847_en-us_VS_110_3_0_2_0_1%], [%$TOPIC/ms617847_en-us_VS_110_3_0_2_0_2%]
type UIElementCollection =  
    class 
        interface [%$TOPIC/ms617847_en-us_VS_110_3_0_3_0_0%] 
        interface [%$TOPIC/ms617847_en-us_VS_110_3_0_3_0_1%] 
        interface [%$TOPIC/ms617847_en-us_VS_110_3_0_3_0_2%] 
    end

The UIElementCollection type exposes the following members.

Constructors
  NameDescription
Public method UIElementCollectionInitializes a new instance of the UIElementCollection class.
Top
Properties
  NameDescription
Public property CapacityGets or sets the number of elements that the UIElementCollection can contain.
Public property CountGets the actual number of elements in the collection.
Public property IsSynchronizedGets a value that indicates whether access to the ICollection interface is synchronized (thread-safe).
Public property ItemGets or sets the UIElement stored at the zero-based index position of the UIElementCollection.
Public property SyncRootGets an object that you can use to synchronize access to the ICollection interface.
Top
Methods
  NameDescription
Public method AddAdds the specified element to the UIElementCollection.
Public method ClearRemoves all elements from a UIElementCollection.
Protected method ClearLogicalParentClears the logical parent of an element when the element leaves a UIElementCollection.
Public method ContainsDetermines whether a specified element is in the UIElementCollection.
Public method CopyTo(Array, Int32)Copies a UIElement from a UIElementCollection to an array, starting at a specified index position.
Public method CopyTo(UIElement, Int32)Copies a UIElement from a UIElementCollection to an array, starting at a specified index position.
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumeratorReturns an enumerator that can iterate the UIElementCollection.
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IndexOfReturns the index position of a specified element in a UIElementCollection.
Public method InsertInserts an element into a UIElementCollection at the specified index position.
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method RemoveRemoves the specified element from a UIElementCollection.
Public method RemoveAtRemoves the UIElement at the specified index.
Public method RemoveRangeRemoves a range of elements from a UIElementCollection.
Protected method SetLogicalParentSets the logical parent of an element in a UIElementCollection.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension Method AsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension Method AsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension Method CastTResultCasts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension Method OfTypeTResultFilters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method IListAddThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see Add.
Explicit interface implemetation Private method IListContainsThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see Contains.
Explicit interface implemetation Private method IListIndexOfThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see IndexOf.
Explicit interface implemetation Private method IListInsertThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see Insert.
Explicit interface implemetation Private property IListIsFixedSizeThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see IsFixedSize.
Explicit interface implemetation Private property IListIsReadOnlyThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see IsReadOnly.
Explicit interface implemetation Private property IListItemThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see Item.
Explicit interface implemetation Private method IListRemoveThis type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see Remove.
Top
Remarks

The Panel base class uses a UIElementCollection to represent its collection of child elements. 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.

A UIElementCollection has affinity to its own context (class). You must access the collection from the context of the owning Panel.

Examples

The following example uses the Add method to add child content to a parent StackPanel. 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);
		}
Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.