FindName function doesn't work
Last post 05-02-2008 2:58 PM by Shaggy8. 3 replies.
Sort Posts:
04-27-2008 6:15 PM
FindName function doesn't work

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.
 

 

 

Shaggy8

Joined on 04-06-2008
Posts 2
04-28-2008 7:53 AM
Marked as Answer
Re: FindName function doesn't work

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.

Don't forget to "Mark as Answer" if this post answered your question
Life's good
My Site

aspdotnetjunkie

Joined on 12-18-2006
Shelton, CT
Posts 80
04-28-2008 8:47 AM
Marked as Answer
Re: FindName function doesn't work

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.

hiteshbhagwat

Joined on 10-05-2007
Posts 18
05-02-2008 2:58 PM
Re: Re: FindName function doesn't work

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.

Shaggy8

Joined on 04-06-2008
Posts 2