UIElementCollection.Add method

Applies to Windows and Windows Phone

Adds a new item to the end of the collection. The item you add must be a UIElement derived element.

Syntax


public void Add(
  UIElement item
)

Parameters

item

Type: UIElement

The new item to add.

Remarks

The Add method will throw an exception if you attempt to add a UIElement to a UIElementCollection and that UIElement already exists in the collection. The Windows Runtime enforces that no UIElement can be the child of more than one parent element, and trying to add the same item twice even to the same parent violates that enforcement.

After you've added an item, you can use the Item indexer to get it by index, or you can use the item reference to continue to refer to that object after it's added to the collection. Or use Contains to verify that a given item exists in a collection.

To add an item to a position in the collection that's not at the collection end, use Insert.

If you are programming using Visual C++ component extensions (C++/CX), the equivalent method is Append.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls

See also

UIElementCollection
Append
Item

 

 

Show:
© 2014 Microsoft