TreeWalker.GetNextSibling 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索指定 AutomationElement 的下一个同级元素。
重载
GetNextSibling(AutomationElement, CacheRequest) |
检索指定的 AutomationElement 的下一个同级元素并缓存属性和模式。 |
GetNextSibling(AutomationElement) |
检索指定 AutomationElement 的下一个同级元素。 |
注解
可以 AutomationElement 具有与当前视图条件不匹配的其他同级元素,因此在导航元素树时不会返回 。
树的结构 AutomationElement 会随着桌面上可见用户界面 (UI) 元素的更改而更改。 不能保证作为下一个同级元素返回的元素将在后续传递中作为下一个同级元素返回。
GetNextSibling(AutomationElement, CacheRequest)
检索指定的 AutomationElement 的下一个同级元素并缓存属性和模式。
public:
System::Windows::Automation::AutomationElement ^ GetNextSibling(System::Windows::Automation::AutomationElement ^ element, System::Windows::Automation::CacheRequest ^ request);
public System.Windows.Automation.AutomationElement GetNextSibling (System.Windows.Automation.AutomationElement element, System.Windows.Automation.CacheRequest request);
member this.GetNextSibling : System.Windows.Automation.AutomationElement * System.Windows.Automation.CacheRequest -> System.Windows.Automation.AutomationElement
Public Function GetNextSibling (element As AutomationElement, request As CacheRequest) As AutomationElement
参数
- element
- AutomationElement
从中检索下一个同级的元素。
- request
- CacheRequest
一个缓存请求对象,它指定返回的 AutomationElement 上要进行缓存的属性和模式。
返回
下一个同级元素;如果不存在此类元素,则为空引用(在 Visual Basic 中为 Nothing
)。
注解
可以 AutomationElement 具有与当前视图条件不匹配的其他同级元素,因此在导航元素树时不会返回 。
树的结构 AutomationElement 会随着桌面上可见用户界面 (UI) 元素的更改而更改。 不能保证作为下一个同级元素返回的元素将在后续传递中作为下一个同级元素返回。
另请参阅
适用于
GetNextSibling(AutomationElement)
检索指定 AutomationElement 的下一个同级元素。
public:
System::Windows::Automation::AutomationElement ^ GetNextSibling(System::Windows::Automation::AutomationElement ^ element);
public System.Windows.Automation.AutomationElement GetNextSibling (System.Windows.Automation.AutomationElement element);
member this.GetNextSibling : System.Windows.Automation.AutomationElement -> System.Windows.Automation.AutomationElement
Public Function GetNextSibling (element As AutomationElement) As AutomationElement
参数
- element
- AutomationElement
从中检索下一个同级元素的 AutomationElement。
返回
下一个同级元素;如果不存在此类元素,则为空引用(在 Visual Basic 中为 Nothing
)。
示例
以下示例演示如何 GetNextSibling 用于构造子树中元素的树视图。
/// <summary>
/// Walks the UI Automation tree and adds the control type of each element it finds
/// in the control view to a TreeView.
/// </summary>
/// <param name="rootElement">The root of the search on this iteration.</param>
/// <param name="treeNode">The node in the TreeView for this iteration.</param>
/// <remarks>
/// This is a recursive function that maps out the structure of the subtree beginning at the
/// UI Automation element passed in as rootElement on the first call. This could be, for example,
/// an application window.
/// CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
/// the desktop could take a very long time and even lead to a stack overflow.
/// </remarks>
private void WalkControlElements(AutomationElement rootElement, TreeNode treeNode)
{
// Conditions for the basic views of the subtree (content, control, and raw)
// are available as fields of TreeWalker, and one of these is used in the
// following code.
AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(rootElement);
while (elementNode != null)
{
TreeNode childTreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType);
WalkControlElements(elementNode, childTreeNode);
elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
}
}
''' <summary>
''' Walks the UI Automation tree and adds the control type of each element it finds
''' in the control view to a TreeView.
''' </summary>
''' <param name="rootElement">The root of the search on this iteration.</param>
''' <param name="treeNode">The node in the TreeView for this iteration.</param>
''' <remarks>
''' This is a recursive function that maps out the structure of the subtree beginning at the
''' UI Automation element passed in as rootElement on the first call. This could be, for example,
''' an application window.
''' CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
''' the desktop could take a very long time and even lead to a stack overflow.
''' </remarks>
Private Sub WalkControlElements(ByVal rootElement As AutomationElement, ByVal treeNode As TreeNode)
' Conditions for the basic views of the subtree (content, control, and raw)
' are available as fields of TreeWalker, and one of these is used in the
' following code.
Dim elementNode As AutomationElement = TreeWalker.ControlViewWalker.GetFirstChild(rootElement)
While (elementNode IsNot Nothing)
Dim childTreeNode As TreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType)
WalkControlElements(elementNode, childTreeNode)
elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode)
End While
End Sub
注解
可以 AutomationElement 具有与当前视图条件不匹配的其他同级元素,因此在导航元素树时不会返回 。
树的结构 AutomationElement 会随着桌面上可见用户界面 (UI) 元素的更改而更改。 不能保证作为下一个同级元素返回的元素将在后续传递中作为下一个同级元素返回。