語言

IRawElementProviderFragment.Navigate(NavigateDirection) 方法

定義

在樹狀結構中指定方向取得 使用者介面自動化 元素。

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

參數

direction
NavigateDirection

該導航的方向。

傳回

指定方向的元素,或 null 是該方向沒有元素。

範例

以下範例程式碼展示了由一個只有單一子元素的片段根來實作 Navigate 。 由於實作元素是片段根,無法導覽至父元素或姊妹元素。

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

以下範例展示了一個片段實作,該片段代表清單框中的單一項目。 在此情況下,該元素允許對其父節點和兄弟姊妹進行導航,但不允許任何子節點。

/// <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

備註

使用者介面自動化 伺服器對此方法的實作定義了 使用者介面自動化 元素樹的結構。

導航必須向上支援至父方,向下支援至第一及最後一位子女,並視情況向向支援至下一位及之前的兄弟姊妹。

每個子節點只有一個父節點,必須被放入由 和 FirstChild從父LastChild節點到達的兄弟節點鏈中。

兄弟姊妹之間的關係必須在雙向上相同:如果A是B的 PreviousSibling,那麼B就是A的 NextSibling。 A FirstChild 沒有,A PreviousSibling 沒有LastChildNextSibling。

片段根無法導向父節點或兄弟姊妹;片段根節點間的導航由預設視窗提供者處理。 片段中的元素只能導向該片段內的其他元素。

適用於

另請參閱