LogicalTreeHelper.FindLogicalNode(DependencyObject, String) LogicalTreeHelper.FindLogicalNode(DependencyObject, String) LogicalTreeHelper.FindLogicalNode(DependencyObject, String) LogicalTreeHelper.FindLogicalNode(DependencyObject, String) Method


嘗試尋找並傳回具有指定之名稱的物件。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.

 static System::Windows::DependencyObject ^ FindLogicalNode(System::Windows::DependencyObject ^ logicalTreeNode, System::String ^ elementName);
public static System.Windows.DependencyObject FindLogicalNode (System.Windows.DependencyObject logicalTreeNode, string elementName);
static member FindLogicalNode : System.Windows.DependencyObject * string -> System.Windows.DependencyObject
Public Shared Function FindLogicalNode (logicalTreeNode As DependencyObject, elementName As String) As DependencyObject


DependencyObject DependencyObject DependencyObject DependencyObject

做為搜尋起點的物件。The object to start searching from. 這個物件必須是 FrameworkElementFrameworkContentElementThis object must be either a FrameworkElement or a FrameworkContentElement.

String String String String

要尋找之物件的名稱。The name of the object to find.


具有相符名稱的物件 (如果找到的話)。如果在邏輯樹狀結構中找不到相符名稱,則傳回 nullThe object with the matching name, if one is found; returns null if no matching name was found in the logical tree.


方法FrameworkContentElement.FindNameFrameworkElement.FindName表面上類似於FindLogicalNode,但運作方式不同的邏輯:The methods FrameworkContentElement.FindName and FrameworkElement.FindName are superficially similar to FindLogicalNode, but operate by different logic:

  • 搜尋方向FindLogicalNode朝向 (向下樹狀目錄); 的子物件的搜尋方向FindName方法正朝向父物件 (向上樹狀目錄中)。The search direction for FindLogicalNode is toward child objects (down the tree); the search direction for the FindName methods is towards parent objects (up the tree).

  • FindName方法受到 XAML 名稱範圍的概念。The FindName methods are governed by the concept of a XAML namescope. 使用FindName保證只有一個該名稱的物件存在,因為 XAML 名稱範圍強制執行唯一性。Using FindName you are guaranteed that only one object of that name exists, because XAML namescopes enforce uniqueness. 相反地,FindLogicalNode在搜尋期間,會忽略 XAML 名稱範圍,可能會跨 XAML 名稱範圍界限。In contrast, FindLogicalNode ignores XAML namescope and might cross XAML namescope boundaries during the search. 因此,則無法保證唯一性的elementName名稱之後跨越界限。As such, there is no guarantee of uniqueness of the elementName name once boundaries are crossed. 如需有關 XAML 名稱範圍的詳細資訊,請參閱 < WPF XAML NamescopesFor more information about XAML namescopes, see WPF XAML Namescopes.