
288Microsoft Visual Studio 2010: A Beginner’s Guide
Similar to WPF applications, Silverlight applications start with a MainPage.xaml file and an App.xaml file, where App.xaml runs to initialize the application and MainPage
.xaml contains the display page. The Web site is a typical ASP.NET MVC application, except that it does have a test page that hosts the Silverlight application, SilverlightDemo CSTestPage.aspx (SilverlightDemoVBTestPage.aspx for VB). There’s also a Silverlight DemoCSTestPage.html (SilverlightDemoVBTestPage.html for VB), which performs the same function as the SilverlightDemoCSTestPage.aspx (SilverlightDemoVBTestPage
.aspx for VB) hosting Silverlight, except that the *.html version uses JavaScript and the HTML object tag to host Silverlight. Listing
Listing 10-1 Hosting a Silverlight application on a Web page
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC
<head runat="server"> <title>SilverlightDemoCS</title> <style type="text/css">
//css styles omitted </style>
<script type="text/javascript" src="Silverlight.js"></script> <script type="text/javascript">
function onSilverlightError(sender, args) {
//error handling code omitted
}
</script>
</head>
<body>
<form id="form1" runat="server" style="height:100%"> <div id="silverlightControlHost">
<object
<param name="source" value="ClientBin/SilverlightDemoCS.xap"/>
<param name="onError" value="onSilverlightError" /> <param name="background" value="white" />