views:

27

answers:

3

Hi, When creating a new Silverlight App, VS2010 generates the following page with the aspx extension

<%@ Page Language="C#"  AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>BmwConfig.SilverlightApp2</title>
    <style type="text/css">
    html, body {
        height: 100%;
        overflow: auto;
    }
    body {
        padding: 0;
        margin: 0;
    }
    #silverlightControlHost {
        height: 100%;
        text-align:center;
    }
    </style>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
              appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
              return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ;

            errMsg += "Code: "+ iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {           
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " +  args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="ClientBin/SilverlightApp2.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="4.0.50401.0" />
          <param name="autoUpgrade" value="true" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50401.0" style="text-decoration:none">
              <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
    </form>
</body>
</html>

I'm not sure how to modify the page so it uses my Master Page

<%@ Page Language="C#"  MasterPageFile="~/Site.master" AutoEventWireup="true" %>

Thanks

A: 

Its really very easy... just consider xap file as just another Flash or any other 3rd party Control you want in your page..

Just Create a WebContentForm, inherit it from any Masterpage and then follow the link in article given below on how to integrate SL in aspx page.

here is the detailed information on how you can integrate XAP in various ways: http://msdn.microsoft.com/en-us/library/cc838145%28VS.95%29.aspx

Regards.

Shoaib Shaikh
A: 

Is it what you are suggesting?

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="BmwConfig.WebApp2.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="form1" runat="server" style="height:100%;">
  <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div  style="height:100%;">
      <asp:Silverlight ID="Xaml1" runat="server" 
        Source="ClientBin/SilverlightApp2.xap" MinimumVersion="2.0" Width="100%" 
        Height="100%" />
   </div>
</form>
</asp:Content>

This gives me the following error

The type or namespace name 'Silverlight' does not exist in the namespace 'System.Web.UI.WebControls' (are you missing an assembly reference?)   

however the page above generated by VS2010 works fine in the same project

bmanu
A: 

Give this a try. It should be close. The idea is to put your style and Javascript portions in the content control for the head portion of the page and put the Silverlight code in the content control for the body of the page.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="BmwConfig.WebApp2.WebForm1" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> 

<style type="text/css"> 
    html, body { 
        height: 100%; 
        overflow: auto; 
    } 
    body { 
        padding: 0; 
        margin: 0; 
    } 
    #silverlightControlHost { 
        height: 100%; 
        text-align:center; 
    } 
    </style> 
    <script type="text/javascript" src="Silverlight.js"></script> 
    <script type="text/javascript"> 
        function onSilverlightError(sender, args) { 
            var appSource = ""; 
            if (sender != null && sender != 0) { 
              appSource = sender.getHost().Source; 
            } 

            var errorType = args.ErrorType; 
            var iErrorCode = args.ErrorCode; 

            if (errorType == "ImageError" || errorType == "MediaError") { 
              return; 
            } 

            var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ; 

            errMsg += "Code: "+ iErrorCode + "    \n"; 
            errMsg += "Category: " + errorType + "       \n"; 
            errMsg += "Message: " + args.ErrorMessage + "     \n"; 

            if (errorType == "ParserError") { 
                errMsg += "File: " + args.xamlFile + "     \n"; 
                errMsg += "Line: " + args.lineNumber + "     \n"; 
                errMsg += "Position: " + args.charPosition + "     \n"; 
            } 
            else if (errorType == "RuntimeError") {            
                if (args.lineNumber != 0) { 
                    errMsg += "Line: " + args.lineNumber + "     \n"; 
                    errMsg += "Position: " +  args.charPosition + "     \n"; 
                } 
                errMsg += "MethodName: " + args.methodName + "     \n"; 
            } 

            throw new Error(errMsg); 
        } 
    </script> 

</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
<form id="form1" runat="server" style="height:100%;"> 
   <div id="silverlightControlHost"> 
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> 
          <param name="source" value="ClientBin/SilverlightApp2.xap"/> 
          <param name="onError" value="onSilverlightError" /> 
          <param name="background" value="white" /> 
          <param name="minRuntimeVersion" value="4.0.50401.0" /> 
          <param name="autoUpgrade" value="true" /> 
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50401.0" style="text-decoration:none"> 
              <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/> 
          </a> 
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div> 
</form> 
</asp:Content> 
DaveB