LogicalTreeHelper.FindLogicalNode(DependencyObject, String) Method

Definition

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

Parameters

logicalTreeNode
DependencyObject

The object to start searching from. This object must be either a FrameworkElement or a FrameworkContentElement.

elementName
String

The name of the object to find.

Returns

The object with the matching name, if one is found; returns null if no matching name was found in the logical tree.

Remarks

The methods FrameworkContentElement.FindName and FrameworkElement.FindName are superficially similar to FindLogicalNode, but operate by different logic:

  • 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).

  • The FindName methods are governed by the concept of a XAML namescope. Using FindName you are guaranteed that only one object of that name exists, because XAML namescopes enforce uniqueness. In contrast, FindLogicalNode ignores XAML namescope and might cross XAML namescope boundaries during the search. As such, there is no guarantee of uniqueness of the elementName name once boundaries are crossed. For more information about XAML namescopes, see WPF XAML Namescopes.

Applies to