Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

UIElementCollection.IndexOf Method

Returns the index position of a specified element in a UIElementCollection.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

abstract IndexOf : 
        element:UIElement -> int  
override IndexOf : 
        element:UIElement -> int

Parameters

element
Type: System.Windows.UIElement

The element whose index position is required.

Return Value

Type: System.Int32
The index position of the element. -1 if the element is not in the collection.

The following example finds the index position of a UIElement within a UIElementCollection.

<DockPanel Name="ParentElement">

    <TextBlock DockPanel.Dock="Top" Name="TxtDisplay"></TextBlock>

    <Button DockPanel.Dock="Top" Click="FindIndex">What is the Index Number
        of the Element Just Added?</Button>
    <DockPanel Name="MainDisplayPanel">
        <TextBlock DockPanel.Dock="Top">Text 1</TextBlock>
        <TextBlock DockPanel.Dock="Top">Text 2</TextBlock>
    </DockPanel>
</DockPanel>

...

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft