Share via


Element.FindByName(String) Method

Definition

Returns the element that has the specified name.

public:
 virtual System::Object ^ FindByName(System::String ^ name);
public object FindByName(string name);
abstract member FindByName : string -> obj
override this.FindByName : string -> obj
Public Function FindByName (name As String) As Object

Parameters

name
String

The name of the element to be found.

Returns

The element that has the specified name, or null if no element with the specified name is found.

Implements

Exceptions

Thrown if the element's namescope couldn't be found.

Remarks

This method searches for named elements within the current namescope. The search scope is determined by traversing up the visual tree from the current element until a namescope is found. Typically, each page, content view, or data template defines its own namescope.

The search is limited to elements that have been registered in the same namescope, which includes:

  • Elements with x:Name attributes defined in XAML within the same namescope
  • Elements manually registered using RegisterName(String, Object)
  • Child elements and their descendants within the same namescope boundary

Elements in different namescopes (such as different pages or data templates) are not accessible from each other through this method.

Applies to