Sdílet prostřednictvím


IRawElementProviderFragment.Navigate(NavigateDirection) Metoda

Definice

Načte prvek model UI Automation v zadaném směru ve stromu.

public:
 System::Windows::Automation::Provider::IRawElementProviderFragment ^ Navigate(System::Windows::Automation::Provider::NavigateDirection direction);
public System.Windows.Automation.Provider.IRawElementProviderFragment Navigate (System.Windows.Automation.Provider.NavigateDirection direction);
abstract member Navigate : System.Windows.Automation.Provider.NavigateDirection -> System.Windows.Automation.Provider.IRawElementProviderFragment
Public Function Navigate (direction As NavigateDirection) As IRawElementProviderFragment

Parametry

direction
NavigateDirection

Směr, ve kterém se chcete pohybovat.

Návraty

IRawElementProviderFragment

Prvek v zadaném směru nebo null pokud neexistuje žádný prvek v daném směru.

Příklady

Následující ukázkový kód ukazuje implementaci Navigate kořenem fragmentu, který má jeden podřízený prvek. Vzhledem k tomu, že implementační prvek je kořen fragmentu, neumožňuje navigaci na nadřazený prvek ani elementy na stejné úroveň.

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;
    };
}
Function Navigate(ByVal direction As NavigateDirection) As IRawElementProviderFragment _
    Implements IRawElementProviderFragment.Navigate

    If direction = NavigateDirection.FirstChild _
        OrElse direction = NavigateDirection.LastChild Then
        ' Return the provider that is the sole child of this one.
        Return CType(ChildControl, IRawElementProviderFragment)
    Else
        Return Nothing
    End If

End Function 'IRawElementProviderFragment.Navigate

Následující příklad ukazuje implementaci fragmentem, který představuje jednu položku v seznamu. V tomto případě prvek umožňuje navigaci na nadřazené a nasouzené, ale ne na žádné podřízené položky.

/// <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;
    }
}
''' <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 Function Navigate(ByVal direction As NavigateDirection) As IRawElementProviderFragment _
    Implements IRawElementProviderFragment.Navigate

    Dim myIndex As Integer = parentItems.IndexOf(Me)
    If direction = NavigateDirection.Parent Then
        Return DirectCast(parentControl, IRawElementProviderFragment)
    ElseIf direction = NavigateDirection.NextSibling Then
        If myIndex < parentItems.Count - 1 Then
            Return DirectCast(parentItems((myIndex + 1)), IRawElementProviderFragment)
        Else
            Return Nothing
        End If
    ElseIf direction = NavigateDirection.PreviousSibling Then
        If myIndex > 0 Then
            Return DirectCast(parentItems((myIndex - 1)), IRawElementProviderFragment)
        Else
            Return Nothing
        End If
    Else
        Return Nothing
    End If

End Function 'Navigate

Poznámky

Implementace této metody model UI Automation serveru definují strukturu stromu elementů model UI Automation.

Navigace musí být podporována směrem nahoru k nadřazenosti, dolů k prvnímu a poslednímu dítěti a později k dalšímu a předchozímu sourozenci podle potřeby.

Každý podřízený uzel má pouze jeden nadřazený uzel a musí být umístěn v řetězu sourozenců dosaženo od nadřazeného objektu a FirstChild LastChild.

Vztahy mezi sourozenci musí být identické v obou směrech: pokud je A je B PreviousSibling, pak B je A NextSibling. A FirstChild nemá žádné PreviousSiblinga LastChild nemá žádné NextSibling.

Kořeny fragmentů neumožňují navigaci na nadřazenou nebo na stejné úrovni; navigace mezi kořeny fragmentů je zpracována výchozími poskytovateli oken. Prvky v fragmentech musí přecházet pouze na jiné prvky v rámci daného fragmentu.

Platí pro

Viz také