Feeds

Get started with Silverlight

A time to shine

Choosing a cloud hosting partner with confidence

The basics

Whichever platform you use to develop, you'll need to install the Silverlight 1.0 runtime for your browser. If you visit a site that uses Silverlight, and you don't yet have the Silverlight runtime installed, you'll be directed to an installation process. The runtime is surprisingly small (less than 2MB). The Silverlight home page lets you install the plug-in and see demonstrations. The Microsoft Silverlight 1.0 Software Development Kit (SDK) is available along with other resources for Windows from MSDN.

A Silverlight application typically consists of XAML markup and JavaScript code. You also need an HTML file to call the application. We'll start with four files:

  • Default.html – the HTML page containing the Silverlight content
  • Silverlight.js – the Microsoft provided runtime file
  • CreateSilverlight.js – some JavaScript that you provide to start your application
  • Scene.xaml – some XAML describing your desired Silverlight content

The HTML contains references to the JavaScript files, provides a DIV tag to host the Silverlight control and then calls the JavaScript code to start the Silverlight content:

<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The Silverlight.js file is a standard file, distributed as part of the Microsoft Silverlight 1.0 SDK and widely available elsewhere on the Web.

The CreateSilverlight.js file defines the createSilverlight() function that is called from the HTML. It finds the DIV tag that will host the Silverlight control and provides the glue to load and start your XAML content (defined in Scene.xaml).

function createSilverlight()
{  
        Silverlight.createObjectEx({
                source: 'Scene.xaml',
                parentElement: document.getElementById('SilverlightPlugInHost'),
                id: 'SilverlightPlugIn',
                properties: {
                        width: '400',
                        height: '400',
                        background:'#ffffff',
            isWindowless: 'false',
                        version: '1.0'
                },
                events: {
                    onError: null,
                        onLoad: null
                },              
                context: null 
        });
}

All the magic happens in Scene.xaml – this is where we define our Hello World application.

<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <TextBlock FontFamily="Times New Roman" 
                           FontSize="70" 
                           FontStyle="Italic" 
                           Foreground="Red"   
                           Text="Hello World" />

</Canvas>

I'll explain the thinking behind XAML in a moment, but for now save these four files to a new directory and load the HTML into your browser. If you are running locally, your browser may warn you about Active X controls and block the content (this isn't the case when you run from a web server). Unblocking should give you a page like this:

Remote control for virtualized desktops

Next page: XAML and Microsoft

More from The Register

next story
Be real, Apple: In-app goodie grab games AREN'T FREE – EU
Cupertino stands down after Euro legal threats
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Bada-Bing! Mozilla flips Firefox to YAHOO! for search
Microsoft system will be the default for browser in US until 2020
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Protecting users from Firesheep and other Sidejacking attacks with SSL
Discussing the vulnerabilities inherent in Wi-Fi networks, and how using TLS/SSL for your entire site will assure security.
Saudi Petroleum chooses Tegile storage solution
A storage solution that addresses company growth and performance for business-critical applications of caseware archive and search along with other key operational systems.