locked
FindName function doesn't work RRS feed

  • Question

  • I can't access any nodes in the Silverlight Object Model using  the recommended functions.  the xaml file I'm using for my silverlight control is:

    <Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Line x:Name="myLine"
          X1="10" Y1="10"
          X2="50" Y2="50"
          Stroke="Black"
          StrokeThickness="4" />

    </Canvas>

    and I've created the Silverlight control using Silverlight.CreateObjet(...) but if I try:


    var oSilverlightControl = document.getElementById(sSilverlightControlId);
    var foundControl = oSilverlightControl.content.FindName("myLine");

     

    to get a reference to the Line object it simply returns null, although oSilverlightControl was found with no problem in the DOM.  Also if I try

     

    var foundRoot = oSilverlightControl.content.Root;

     

    it also returns null.

     

    What am I missing here??? I can't seem to access a single Silverlight object using javascript, and all the documentation I've found is no help, since as far as I can tell they do the same thing I'm doing.
     

     

     

    Sunday, April 27, 2008 6:15 PM

Answers

  • Not sure when you're firing this code but you can only access silverlight specific members on this object after it finishes loading, meaning after its onLoad event is raised.

    Monday, April 28, 2008 7:53 AM
  • Hello Shaggy,

    You have getting only reffernce to Div of html ,not the reffernce of silverlight plugin for that

    you have to write the Id of silverlight plugin.This Id is written in create silverlight function in Default.html.js file.By default it is "SilverlightControl".

    If you are acessing from html you have get first silverlight plugin reffernce then,using this plugin reffernce u have to take root reffernce.

    Monday, April 28, 2008 8:47 AM

All replies

  • Not sure when you're firing this code but you can only access silverlight specific members on this object after it finishes loading, meaning after its onLoad event is raised.

    Monday, April 28, 2008 7:53 AM
  • Hello Shaggy,

    You have getting only reffernce to Div of html ,not the reffernce of silverlight plugin for that

    you have to write the Id of silverlight plugin.This Id is written in create silverlight function in Default.html.js file.By default it is "SilverlightControl".

    If you are acessing from html you have get first silverlight plugin reffernce then,using this plugin reffernce u have to take root reffernce.

    Monday, April 28, 2008 8:47 AM
  • I ended up having to call the javascript in an onload event handler for the page (body) as the div element I'm interested in doesn't raise an onload event, but it worked.  Thanks for your help.

    Friday, May 2, 2008 2:58 PM