I spent about 2 hours trying to figure this out today so I thought I'd just share it here. Mostly, the time lost comes down to Javascript but that's no big surprise :-(
Essentially, I'm playing with the HTML Bridge that lets Silverlight .NET code call Javascript code and vice versa. It's all working very smoothly until I want to create an instance of a .NET type ( marked as ScriptableType ) from Javascript.
I know that somewhere, there's a method that may be called;
createObject
createManagedObject
createManagedInstance
but I can't figure out what the heck it's called and I can't figure out a decent way of figuring that out :-)
So...with Silverlight 2 Beta 1 I can confirm that if you have a .NET type such as;
[ScriptableType]
public class Point
{
[ScriptableMember]
public int X { get; set; }
[ScriptableMember]
public int Y { get; set; }
}
and if you've registered this for use from Javascript at some point by calling something like this ( from .NET code );
HtmlPage.RegisterCreateableType("PointType", typeof(Point));
Then you should be able to create one of those from script with something like;
var plugin = $get("Xaml1");
plugin.content.services.createObject("PointType");
Note that my plugin ID is "Xaml1" here as generated by Visual Studio.