Export (0) Print
Expand All

FindName (Silverlight Plug-in)

Silverlight

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

retval = silverlightObject.content.FindName(objectName)

objectName

string

The name of the object to get.

Type: object

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

FrameworkElement.FindName (or TextElement.FindName). XAML namescopes work a bit differently in the managed API; see XAML Namescopes.

This method is available on the content subobject of a Silverlight plug-in instance.

You can find any named object in the Silverlight object hierarchy by using the FindName method of the Silverlight plug-in and referencing the object's x:Name or Name attribute value. The object you are searching for can be any named object in the Silverlight object hierarchy. If the method is successful, it returns a reference to the object; otherwise, it returns null.

The behavior of FindName potentially depends on how or whether discrete XAML namescopes exist in your markup. For more information, see XAML and XAML-Related Concepts in the JavaScript API for Silverlight.

Because FindName relies on all XAML being parsed for the Name attributes, you should not attempt to call FindName until the XAML is loaded. You can assure this by calling FindName as part of a Loaded handler, or can use other user-driven event handlers that implicitly can occur only once the user interface is loaded.

The following JavaScript example shows how use the FindName method.

function onLoaded(sender, eventArgs)
{
    // Retrieve a reference to the plug-in.
    var slPlugin = sender.getHost();

    // Retrieve a reference to the specified object.
    var object = slPlugin.content.findName("myTextBlock");

    // If the object reference is valid, display an alert dialog box.
    if (object != null)
    {
        alert(object.toString() + " found");
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft