background preloader

Silverlight

Facebook Twitter

Calling JavaScript functions from Silverlight 2. Abstract: Silverlight 2 is a great technology to build business centric applications, and one of the coolest features is the ability to call JavaScript functions from your Silverlight code.

Calling JavaScript functions from Silverlight 2

The following article demonstrates how to use call JavaScript from Silverlight 2. Calling JavaScript functions from Silverlight 2 Silverlight 2 is a great technology to build business centric applications, and one of the coolest features is the ability to call JavaScript functions from your Silverlight code. To begin with, Open Visual Studio 2008 and choose File > New > Project > Silverlight > Silverlight Application.

In the web application, add a new JavaScript file to the project and name it MyFunctions.js. Configuring IIS for Silverlight Applications : Web Server For Shared Hosting : Configuring Servers. Introduction Microsoft® SilverlightTM is a cross-browser, cross-platform plug-in for delivering the next generation of .NET-based media experiences and rich interactive applications for the Web.

Configuring IIS for Silverlight Applications : Web Server For Shared Hosting : Configuring Servers

Silverlight offers a flexible programming model that supports AJAX, VB, C#, Python, and Ruby, and integrates with existing Web applications. Making Silverlight Scriptable by JavaScript. Public class MyStockWatcher { [ScriptableMemberAttribute] public string SomeProperty {get; set;} [ScriptableMemberAttribute] public event EventHandler SomeEvent; [ScriptableMemberAttribute] public string DoWork(int count); } Registration can occur in the App class, the Page class, classes connected to the App or Page class by namespace, or in managed event handlers, as the following code demonstrates. public CustomCanvas : Canvas { public static void Canvas_Loaded(object o, EventArgs e) { MyStockWatcher m = new MyStockWatcher(); HtmlPage.RegisterScriptableObject("stockwatcher", m); } } As soon as you register an instance of a scriptable type, JavaScript code can access the scriptable members of that type by using the Content property of the Silverlight plug-in object.

Making Silverlight Scriptable by JavaScript

The general rules for marking types as scriptable are as follows: