IRawElementProviderFragment.Navigate(NavigateDirection) メソッド

定義

ツリー内の指定した方向のUI オートメーション要素を取得します。

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 方向に要素がない場合。

次のコード例は、1 つの子要素を持つフラグメント ルートによる実装 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

次の例は、リスト ボックス内の 1 つの項目を表すフラグメントによる実装を示しています。 この場合、要素は親と兄弟へのナビゲーションを有効にしますが、子には移動できません。

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

注釈

このメソッドのUI オートメーション サーバーの実装は、UI オートメーション要素ツリーの構造を定義します。

ナビゲーションは、親に対して上向き、最初と最後の子に下向き、および次の兄弟と前の兄弟に対して、必要に応じて横向きにサポートする必要があります。

各子ノードには親が 1 つだけあり、親からFirstChildLastChild到達した兄弟のチェーンに配置する必要があります。

兄弟間の関係は両方向で同じである必要があります。A が B の PreviousSibling場合、B は A NextSiblingです。 A FirstChild にはいいえPreviousSibling、a LastChild には .NextSibling

フラグメント ルートでは、親または兄弟へのナビゲーションは有効になりません。フラグメント ルート間のナビゲーションは、既定のウィンドウ プロバイダーによって処理されます。 フラグメント内の要素は、そのフラグメント内の他の要素にのみ移動する必要があります。

適用対象

こちらもご覧ください