tags:

views:

163

answers:

1

Hi,

I've tried to Google for this but maybe I'm not forming my query right, 'cos I am getting a lot of nonsense and irrelevance back. Probably too simple a question. Apologies it's been a while since I last did Silverlight!

If I have a XAML element:

<Image Canvas.Top="128" x:Name="img4_7" Width="180.3" Height="117" Source="monkey1.jpg" Stretch="Fill" Canvas.Left="-3.344" Opacity="0.595"/>

How can I get that in JavaScript using the x:Name? I'm looking for something like getElementById(), but for Silverlight. I almost want something like this:

img4_7=rootElement.children.getItem('img4_7');

Obviously, this doesn't work!

I'm not using ASP.NET AJAX.

Thanks for any help for this noob question!

+1  A: 

Figured it out.

Need to use control.content.findName()

Here's my handLoad, for others to benefit:

handleLoad: function(control, userContext, rootElement) 
{
 this.control = control;

 // Sample event hookup: 
 rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));

 this.img4_7=control.content.findName("img4_7"); 

 if (this.img4_7) {
  this.img4_7.addEventListener("MouseEnter", Silverlight.createDelegate(this,this.handleMouseEnter));
  this.img4_7.addEventListener("MouseLeave",Silverlight.createDelegate(this,this.handleMouseLeave));

 }


},
Program.X