LogicalTreeHelper 类


提供用于查询逻辑树中的对象的静态帮助器方法。Provides static helper methods for querying objects in the logical tree.

public ref class LogicalTreeHelper abstract sealed
public static class LogicalTreeHelper
type LogicalTreeHelper = class
Public Class LogicalTreeHelper


LogicalTreeHelper类提供的方法可用于返回对象的子集合,或从逻辑树的子节点内返回特定对象。The LogicalTreeHelper class provides methods that you can use to return child collections of objects, or specific objects from within subnodes of the logical tree. 但是,您通常执行的大多数对象树操作也由或上的类似方法或属性公开 FrameworkElement FrameworkContentElementHowever, most of the object tree operations that you typically perform are also exposed by similar methods or properties on FrameworkElement or FrameworkContentElement. 例如,尝试下列操作:For example, try the following:

  • 不调用 GetChildren 返回逻辑子对象的枚举器的静态方法,而是使用在该对象的内容模型中公开的专用集合。Instead of calling the static GetChildren method, which returns an enumerator for the logical child objects, use the dedicated collection exposed in the content model for that object. 几乎所有支持内容模型的对象都公开了某些包含子对象集合的属性,并直接在该集合上提供集合接口支持。Nearly all objects that support a content model expose some property that contains the collection of child objects, and provides collection interface support directly on that collection.

  • 不是调用静态 FindLogicalNode 方法来通过指定子对象的名称来获取子对象,而是对 FrameworkElement.FindName FrameworkContentElement.FindName 特定对象调用或方法。Instead of calling the static FindLogicalNode method to obtain a child object by specifying its name, call the FrameworkElement.FindName or FrameworkContentElement.FindName method on specific objects.

LogicalTreeHelper 对于分析方案非常有用,在这种情况下,将以递归方式遍历逻辑树,并使用一致的方法检查各种父对象或子对象。LogicalTreeHelper is most useful for analysis scenarios where you are traveling up or down the logical tree recursively through multiple levels, and want to use a consistent approach for examining the various parent or child objects. 在这种情况下,你可能会访问混合内容模型,使用更多内容模型的特定 Api 会过于复杂。In this case, you might be accessing a mixture of content models, and using the more content-model specific APIs would be too complex.



尝试使所请求的 UI 元素可见,并在目标上引发 RequestBringIntoView 事件以报告结果。Attempts to bring the requested UI element into view and raises the RequestBringIntoView event on the target in order to report the results.

FindLogicalNode(DependencyObject, String)

尝试查找并返回具有指定名称的对象。Attempts to find and return an object that has the specified name. 搜索从指定对象开始,并持续到逻辑树的子节点中。The search starts from the specified object and continues into subnodes of the logical tree.


通过处理逻辑树返回指定的对象的即时子对象集合。Returns the collection of immediate child objects of the specified object, by processing the logical tree.


通过处理逻辑树,返回指定 FrameworkContentElement 的直接子对象的集合。Returns the collection of immediate child objects of the specified FrameworkContentElement by processing the logical tree.


通过处理逻辑树,返回指定 FrameworkElement 的直接子对象的集合。Returns the collection of immediate child objects of the specified FrameworkElement by processing the logical tree.


通过处理逻辑树,返回指定对象的父对象。Returns the parent object of the specified object by processing the logical tree.