2010-07-14 84 views
0

當創建一個新的Silverlight應用程序,VS2010與ASPX擴展產生如下頁面母版頁包含Silverlight應用程序的aspx頁面

<%@ 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"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>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&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> 

我不知道怎麼那麼它使用我的主人修改頁面第

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

感謝

回答

0

試試這個工作正常。它應該接近。我們的想法是將您的樣式和Javascript部分放在頁面頭部的內容控件中,並將Silverlight代碼放置在頁面主體的內容控件中。

<%@ 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&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> 
0

它真的很不容易......只考慮XAP文件只是另一個Flash或你在你的頁面需要的任何其他第三方控制..

只需創建一個WebContentForm,從任何Masterpage繼承它,然後按照下面給出的關於如何將SL集成到aspx頁面的文章中的鏈接。

這裏是你如何能以各種方式XAP整合的詳細信息: http://msdn.microsoft.com/en-us/library/cc838145%28VS.95%29.aspx

問候。

0

這是你的建議嗎?

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="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> 

這給了我下面的錯誤

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

但是通過VS2010生成上面的頁面在同一個項目

1

回答已經太遲了,但可能對正在尋找答案的其他人有幫助。

所有JavaScript代碼都轉到標頭佔位符,並由DaveB先前聲明。

<asp:Content ID="Content1" ContentPlaceHolderID="MySiteMasterHeaderPlaceholder" Runat="Server"> 
    // JavaScript code goes here 
</asp:Content> 

您不使用Content標籤中的第二個表單標籤,因爲它已經在母版頁上聲明。

<asp:Content ID="Content2" ContentPlaceHolderID="MySiteMasterContentPlaceholder" Runat="Server"> 
    <div id="silverlightControlHost"> 
     <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="730px" height="250px"> 
      <param name="source" value="MainAssetsSearch.xap" /> 
      <param name="onError" value="onSilverlightError" /> 
      <param name="background" value="white" /> 
      <param name="minRuntimeVersion" value="4.0.50826.0" /> 
      <param name="autoUpgrade" value="true" /> 
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.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" /> 
    </div> 
</asp:Content> 

,並避免使用width="100%"height="250%"因爲Firefox會不會使Silverlight內容。

相關問題