UIElementCollection.Item property

Applies to Windows and Windows Phone

Gets or sets the element at the specified index.

Syntax


public UIElement this[int index] { get; set; }

Property value

Type: UIElement

The element at the specified index.

Remarks

The Item indexer property provides the support for a collection indexer syntax in C# and Microsoft Visual Basic. By using this syntax you can index directly on property values such as Panel.Children, where the property uses UIElementCollection as its type. You don't have to explicitly specify the UIElementCollection type, and the strings "Item" or this don't appear in the usage syntax at all.

The collection is zero-indexed. You specify the indexed value you want by enclosing the index number within square brackets if using C#, or parentheses if using Visual Basic. For example, you can use this code to get the first item in the Children collection of a Grid panel named grid1:


UIElement item1 = grid1.Children[0];

The Item indexer property is settable, so you can use the indexer syntax to replace the value of an existing item in the collection. Setting to an existing item in the collection using the indexer syntax won't expand the collection, and the item you replace won't be in the collection anymore. If you want to expand the collection, use Insert (to add to the start or middle) or Add (to add to the end).

Using the indexer syntax with an index value that's greater than or equal to the Count value of the collection throws an exception; you can't use the indexer syntax to set to an index that doesn't exist yet.

If you don't know the index of an item in a collection, you can call IndexOf.

If you are programming using Visual C++ component extensions (C++/CX), see GetAt and SetAt.

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
Insert
IndexOf

 

 

Show:
© 2014 Microsoft