LogicalTreeHelper LogicalTreeHelper LogicalTreeHelper LogicalTreeHelper Class


提供靜態 Helper 方法來查詢邏輯樹狀中的物件。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. 不過,大部分的物件樹狀目錄中執行作業,通常也會公開類似的方法或屬性上FrameworkElementFrameworkContentElementHowever, 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.FindNameFrameworkContentElement.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.


BringIntoView(DependencyObject) BringIntoView(DependencyObject) BringIntoView(DependencyObject) BringIntoView(DependencyObject)

嘗試將所要求的 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) FindLogicalNode(DependencyObject, String) FindLogicalNode(DependencyObject, String) 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.

GetChildren(DependencyObject) GetChildren(DependencyObject) GetChildren(DependencyObject) GetChildren(DependencyObject)

透過處理邏輯樹狀,傳回所指定物件的立即子物件集合。Returns the collection of immediate child objects of the specified object, by processing the logical tree.

GetChildren(FrameworkContentElement) GetChildren(FrameworkContentElement) GetChildren(FrameworkContentElement) GetChildren(FrameworkContentElement)

藉由處理邏輯樹狀結構,傳回指定之 FrameworkContentElement 的直接子物件集合。Returns the collection of immediate child objects of the specified FrameworkContentElement by processing the logical tree.

GetChildren(FrameworkElement) GetChildren(FrameworkElement) GetChildren(FrameworkElement) GetChildren(FrameworkElement)

藉由處理邏輯樹狀結構,傳回指定之 FrameworkElement 的直接子物件集合。Returns the collection of immediate child objects of the specified FrameworkElement by processing the logical tree.

GetParent(DependencyObject) GetParent(DependencyObject) GetParent(DependencyObject) GetParent(DependencyObject)

藉由處理邏輯樹狀結構,傳回指定之物件的父物件。Returns the parent object of the specified object by processing the logical tree.