Feeds

Get started with Silverlight

A time to shine

Secure remote control for conventional and virtual desktops

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:

The essential guide to IT transformation

Next page: XAML and Microsoft

More from The Register

next story
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
Mozilla's 'Tiles' ads debut in new Firefox nightlies
You can try turning them off and on again
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
Scratched PC-dispatch patch patched, hatched in batch rematch
Windows security update fixed after triggering blue screens (and screams) of death
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
prev story

Whitepapers

Endpoint data privacy in the cloud is easier than you think
Innovations in encryption and storage resolve issues of data privacy and key requirements for companies to look for in a solution.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Advanced data protection for your virtualized environments
Find a natural fit for optimizing protection for the often resource-constrained data protection process found in virtual environments.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Next gen security for virtualised datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.