IRawElementProviderFragment.Navigate(NavigateDirection) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索树中指定方向的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
导航方向。
返回
指定方向的元素,或者 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
注解
此方法UI 自动化服务器的实现定义UI 自动化元素树的结构。
导航必须向上支持到父级,向下到第一个和最后一个子级,以及横向到下一个和以前的同级,如适用。
每个子节点只有一个父节点,并且必须放置在从父 FirstChild 节点到达的同级链中 LastChild。
兄弟姐妹之间的关系必须双向相同:如果 A 是 B,PreviousSibling则 B 是 A。NextSibling A FirstChild 没有PreviousSibling,没有LastChildNextSibling。
片段根不支持导航到父级或同级;片段根之间的导航由默认窗口提供程序处理。 片段中的元素只能导航到该片段中的其他元素。