UIElementCollection.First Method

Definition

Returns the iterator object that can iterate over the items in the UIElementCollection.

Equivalent WinUI method: Microsoft.UI.Xaml.Controls.UIElementCollection.First.

public:
 virtual IIterator<UIElement ^> ^ First() = IIterable<UIElement ^>::First;
IIterator<UIElement> First();
public IIterator<UIElement> First();
function first()
Public Function First () As IIterator(Of UIElement)

Returns

IIterator<UIElement>

The iterator object. The iterator's current position is at the 0-index position, or at the collection end if the collection is empty.

Implements

Remarks

A convenient way to hold the iterator returned by First is to assign the return value to a variable that is declared with the auto type deduction keyword. Then use IIterator API as part of a while loop. For example:

auto iterator1{ uieCollection.First() };
while (iterator1.HasCurrent())
{
    Windows::UI::Xaml::UIElement currentItem{ iterator1.Current() };
    // Your logic here that does something with currentItem.
    iterator1.MoveNext();
}
auto iterator1 = uieCollection->First();
while (iterator1->HasCurrent)
{
    auto currentItem = iterator1->Current;
    //your logic here that does something with currentItem
    iterator1->MoveNext();
}

Applies to

See also