Export (0) Print
Expand All

FindName Method

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Gets any object in the Silverlight object hierarchy by referencing the object's x:Name attribute value.

XAML
You cannot use methods in XAML.
Scripting
value = object.findName(name)

Parameters

name String

The name of the object to get.

Return Value

A reference to the specified object if the object was successfully found; otherwise, returns null.

Remarks

You can find any object in the Silverlight object hierarchy by using the FindName method and referencing the object's x:Name attribute value. This means that the object you are searching for does not have to be a direct descendant of the object that invokes the? findName method. If the method is successful, a reference to the object is returned; otherwise, null is returned. The following JavaScript example shows how a leaf node of a Silverlight object hierarchy can access a root node.

JavaScript
// Loaded event handler for the root Canvas object.
function onLoaded(sender, eventArgs)
{
    // Retrieve the object corresponding to the x:Name attribute value.
    var canvas = sender.findName("rootCanvas");

    // Determine whether the object was found.
    if (canvas != null)
    {
        alert(canvas.toString());
    }
    else
    {
        alert("Object not found");
    }
}

You can set or get a property directly on the returned value of the FindName method. The following JavaScript example shows how to combine the FindName and SetValue operations as a combined operation:

JavaScript
    // Set the property on the retrieved object.
    sender.findName("statusTextBlock").text = "Press OK to continue.";

Applies To

UIElement

See Also

Referencing and Modifying Objects, Name

Show:
© 2014 Microsoft