08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 15 ■ ENHANCING THE WEB EXPERIENCE WITH SILVERLIGHT 357<br />

<br />

<br />

<br />

However, if you do this, you will be making life unnecessarily difficult for yourself, as<br />

you will have to manage the location of the XAML, manage the downloading <strong>and</strong> licensing<br />

of the component, <strong>and</strong> so on.<br />

Instead, the <strong>Silverlight</strong> SDK provides tools that make the process a lot easier, <strong>and</strong> that<br />

provide a de facto st<strong>and</strong>ard methodology of using <strong>Silverlight</strong> on your site.<br />

In the rest of this section, you’ll look at all the pieces that you would use to build any<br />

<strong>Silverlight</strong> application, from a simple Hello World application to a full-featured web<br />

experience.<br />

Using <strong>Silverlight</strong>.js<br />

Microsoft provides the file <strong>Silverlight</strong>.js as part of the <strong>Silverlight</strong> SDK. This file contains<br />

everything that you need to instantiate <strong>and</strong> use the <strong>Silverlight</strong> plug-in on your page. It<br />

manages what to do with different browser versions, <strong>and</strong> provides a download location<br />

<strong>and</strong> terms-of-service <strong>and</strong> license information to the end user, making the download<br />

process safe, secure, <strong>and</strong> easy.<br />

As <strong>Silverlight</strong> is a browser plug-in, it is hosted in an HTML page, <strong>and</strong> your page<br />

should have a script reference to this JavaScript file. This will look something like this:<br />

<br />

The <strong>Silverlight</strong> SDK can be downloaded from the Microsoft <strong>Silverlight</strong> site, at<br />

http://silverlight.net/GetStarted/.<br />

You’ll see in a moment how this JavaScript library is used to create a <strong>Silverlight</strong> application—but<br />

first, let’s look at the XAML that it will render.<br />

Using XAML<br />

You saw XAML earlier in this book as a markup language for WPF. <strong>Silverlight</strong> uses a subset<br />

of this language.<br />

This sample contains a XAML Canvas, the basic drawing block <strong>and</strong> container in<br />

<strong>Silverlight</strong>, which in turn contains a TextBlock, which is used for rendering text. This text<br />

is a simple “Hello World!” message.<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!