LogicalTreeHelper.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.

public:
 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

參數

logicalTreeNode
DependencyObject

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

elementName
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.

備註

FindLogicalNodeFrameworkContentElement.FindName 方法的表面上很類似,但會以不同的邏輯操作:FrameworkElement.FindNameThe 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 名稱範圍For more information about XAML namescopes, see WPF XAML Namescopes.

適用於