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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

358<br />

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

Background="White"<br />

x:Name="Page"><br />

<br />

<br />

As you can see, this is straightforward XML, with the st<strong>and</strong>ard parent/child format.<br />

The element is a child of the element, <strong>and</strong> thus it is contained by it.<br />

This XAML would typically be saved as a file called Page.xaml or something similar.<br />

The rest of this example assumes that it is called Page.xaml.<br />

Creating an Instance of the <strong>Silverlight</strong> Plug-In<br />

The <strong>Silverlight</strong>.js library contains the createObject <strong>and</strong> createObjectEx functions, which<br />

are used to generate the correct or tag to create the <strong>Silverlight</strong> component<br />

for the current browser. These functions perform identical tasks, the difference<br />

between them being that createObjectEx uses the JSON notation for bundling parameters<br />

as a matter of convenience.<br />

It is good programming practice to separate this call from the page hosting it so that<br />

the details of the parameters used for the <strong>Silverlight</strong> component are externalized. So, for<br />

example, the HTML markup for the page would look something like this:<br />

<br />

<br />

<br />

create<strong>Silverlight</strong>();<br />

<br />

<br />

<br />

The create<strong>Silverlight</strong> function would be hosted in an external JavaScript file that is<br />

referenced by the HTML. This function would then call createObject or createObjectEx<br />

like this:<br />

function create<strong>Silverlight</strong>()<br />

{<br />

<strong>Silverlight</strong>.createObjectEx({<br />

source: "Page.xaml",<br />

parentElement: document.getElementById("<strong>Silverlight</strong>ControlHost"),<br />

id: "<strong>Silverlight</strong>Control",<br />

properties: {<br />

width: "100%",<br />

height: "100%",

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

Saved successfully!

Ooh no, something went wrong!