IRawElementProviderFragment.Navigate Method (NavigateDirection)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Retrieves the UI Automation element in a specified direction within the tree.

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

IRawElementProviderFragment Navigate(
	NavigateDirection direction
)

Parameters

direction
Type: System.Windows.Automation.Provider.NavigateDirection

The direction in which to navigate.

Return Value

Type: System.Windows.Automation.Provider.IRawElementProviderFragment

The element in the specified direction, or null if there is no element in that direction

The UI Automation server's implementations of this method define the structure of the UI Automation element tree.

Navigation must be supported upward to the parent, downward to the first and last child, and laterally to the next and previous siblings, as applicable.

Each child node has only one parent and must be placed in the chain of siblings reached from the parent by FirstChild and LastChild.

Relationships among siblings must be identical in both directions: if A is B's PreviousSibling, then B is A's NextSibling. A FirstChild has no PreviousSibling, and a LastChild has no NextSibling.

Fragment roots do not enable navigation to a parent or siblings; navigation among fragment roots is handled by the default window providers. Elements in fragments must navigate only to other elements within that fragment.

The following example code shows the implementation of Navigate by a fragment root that has a single child element. Because the implementing element is a fragment root, it does not enable navigation to a parent element or sibling elements.

IRawElementProviderFragment IRawElementProviderFragment.Navigate(NavigateDirection direction)
{
    if ((direction == NavigateDirection.FirstChild)
        || (direction == NavigateDirection.LastChild)) 
    {
        // Return the provider that is the sole child of this one.
        return (IRawElementProviderFragment)ChildControl;
    }
    else
    {
        return null;
    };
}

The following example shows an implementation by a fragment that represents a single item within a list box. In this case, the element enables navigation to its parent and siblings, but not to any children.

/// <summary>
/// Navigate to adjacent elements in the automation tree.
/// </summary>
/// <param name="direction">Direction to navigate.</param>
/// <returns>The element in that direction, or null.</returns>
/// <remarks>
/// parentControl is the provider for the list box.
/// parentItems is the collection of list item providers.
/// </remarks>
public IRawElementProviderFragment Navigate(NavigateDirection direction)
{
    int myIndex = parentItems.IndexOf(this);
    if (direction == NavigateDirection.Parent)
    {
        return (IRawElementProviderFragment)parentControl;
    }
    else if (direction == NavigateDirection.NextSibling)
    {
        if (myIndex < parentItems.Count - 1)
        {
            return (IRawElementProviderFragment)parentItems[myIndex + 1];
        }
        else
        {
            return null;
        }
    }
    else if (direction == NavigateDirection.PreviousSibling)
    {
        if (myIndex > 0)
        {
            return (IRawElementProviderFragment)parentItems[myIndex - 1];
        }
        else return null;
    }
    else return null;
}

.NET Framework
Available since 3.0
Return to top
Show: