共用方式為


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

在其中要瀏覽的方向。

傳回

IRawElementProviderFragment

指定方向的專案,如果該方向沒有元素,則 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 FirstChild沒有 PreviousSibling ,而且 LastChild 沒有 NextSibling

片段根目錄無法巡覽至父代或同層級;片段根目錄之間的巡覽是由預設視窗提供者處理。 片段中的專案只能巡覽至該片段中的其他專案。

適用於

另請參閱