How to Create Silverlight Apps With JavaScript
Silverlight server-web applications can execute on client machines, communicate with servers and services over the Internet and are regarded as safe and secure. A Silverlight application consists of four files which include a Silverlight.js file, a Hyper Text Markup Language (HTML) hosting file, an Extensible Application Markup Language (XAML) file and a JavaScript file that supports the HTML file.
Instructions
-
Silverlight.js File
-
1
Navigate to the Silverlight SDK location on your local drive and locate the Silverlight.js file. The default location is:
C:\Program Files\Microsoft Silverlight (Ver) SDK\Tools\Silverlight.js
-
2
Copy this file into a folder where you will also include all your other files necessary to create your Silverlight application.
-
-
3
Create a new text document in this folder and give it an appropriate name. Add the file extension ".htm."
-
4
Reference the Silverlight.js file by writing the code below inside the HTML file "head" tags:
<head>
<title>Silverlight App</title>
<script type= "text/javascript" src= "Silverlight.js">
</script>
<script type= "text/javascript" src= "CreateSilverlight.js">
</script>
</head>
The above code references the "Silverlight.js" file that we copied. The "CreateSilverlight.js" is created separately.
CreateSilverlight.js File
-
5
Create a new text document in the same folder and rename it "CreateSilverlight.js."
-
6
Copy and paste the JavaScript code below inside the "CreateSilverlight.js" file:
Function createMySilverlightControl()
Var parentElement = document.getElementById( "mySilverlightControlHost");
Silverlight.createObject(
"SilverlightApp.xaml",
parentElement,
"mySilverlightControl",
{
Width: '300',B00011';
isWindowless: 'false',
framerate: '24',
version: 2.0',
Heigh: '300',
inplaceInstallPrompt:true,
background: '#B00001',
{
onError: null,
onLoad:null
},
Null);
}
There is a reference to "SilverlightApp.xaml." Ensure that this file resides in the same folder as all the files.
-
7
Test the Silverlight application by double-clicking on the HTML file you created in the folder. Allow blocked content when prompted and view your application. If the application is working, contents of the "SilverlightApp.xaml" file will be displayed.
-
1
Tips & Warnings
When using the Silverlight Streaming service offered by Microsoft, update the "src" tag inside your HTML file from "Silverlight.js" to "http://agappdom.net/h/silverlight.js."
The script tag should read as follows:
<script type= "text/javascript" src= http://agappdom.net/h/silverlight.js></script>
Package all the files in a compressed file and include a "manifest.xml" file that contains extra parameters.
If you want to capture the URL of a hosted application on Silverlight Streaming Service, log in to your Silverlight Streaming account and manage your applications (see Resources).
Do not attempt to display a Silverlight application on a public website if it contains confidential information. Silverlight applications on a hosted service are not secure.
References
Resources
- Photo Credit businessman and laptop isolated image by Alexey Klementiev from Fotolia.com