Skip to main content
.NET Framework Class Library
UIElementCollectionAdd Method

Adds the specified element to the UIElementCollection.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
Syntax
Public Overridable Function Add ( _
	element As [%$TOPIC/ms603589_en-us_VS_110_2_0_0_0_0%] _
) As [%$TOPIC/ms603589_en-us_VS_110_2_0_0_0_1%]
public virtual [%$TOPIC/ms603589_en-us_VS_110_2_0_1_0_0%] Add(
	[%$TOPIC/ms603589_en-us_VS_110_2_0_1_0_1%] element
)
public:
virtual [%$TOPIC/ms603589_en-us_VS_110_2_0_2_0_0%] Add(
	[%$TOPIC/ms603589_en-us_VS_110_2_0_2_0_1%]^ element
)
abstract Add : 
        element:[%$TOPIC/ms603589_en-us_VS_110_2_0_3_0_0%] -> [%$TOPIC/ms603589_en-us_VS_110_2_0_3_0_1%]  
override Add : 
        element:[%$TOPIC/ms603589_en-us_VS_110_2_0_3_0_2%] -> [%$TOPIC/ms603589_en-us_VS_110_2_0_3_0_3%]
public function Add(
	element : [%$TOPIC/ms603589_en-us_VS_110_2_0_4_0_0%]
) : [%$TOPIC/ms603589_en-us_VS_110_2_0_4_0_1%]

Parameters

element
Type: System.WindowsUIElement

The UIElement to add.

Return Value

Type: SystemInt32
The index position of the added element.
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.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1