Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 带有包含Silverlight应用程序的Aspx页面的母版页_Asp.net_Silverlight - Fatal编程技术网

Asp.net 带有包含Silverlight应用程序的Aspx页面的母版页

Asp.net 带有包含Silverlight应用程序的Aspx页面的母版页,asp.net,silverlight,Asp.net,Silverlight,在创建新的Silverlight应用程序时,VS2010会生成以下带有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="htt

在创建新的Silverlight应用程序时,VS2010会生成以下带有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>

SilverlightApp2
html,正文{
身高:100%;
溢出:自动;
}
身体{
填充:0;
保证金:0;
}
#silverlightControlHost{
身高:100%;
文本对齐:居中;
}
函数onSilverlightError(发送方,参数){
var-appSource=“”;
if(发件人!=null&&sender!=0){
appSource=sender.getHost().Source;
}
var errorType=args.errorType;
var iErrorCode=args.ErrorCode;
如果(errorType==“ImageError”| | errorType==“MediaError”){
返回;
}
var errMsg=“Silverlight应用程序中未处理的错误”+appSource+“\n”;
errMsg+=“代码:”+iErrorCode+“\n”;
errMsg+=“类别:”+errorType+“\n”;
errMsg+=“消息:”+args.ErrorMessage+“\n”;
如果(errorType==“ParserError”){
errMsg+=“文件:”+args.xamlFile+“\n”;
errMsg+=“行:”+args.lineNumber+“\n”;
errMsg+=“位置:”+args.charPosition+“\n”;
}
else if(errorType==“RuntimeError”){
如果(args.lineNumber!=0){
errMsg+=“行:”+args.lineNumber+“\n”;
errMsg+=“位置:”+args.charPosition+“\n”;
}
errMsg+=“MethodName:”+args.MethodName+“\n”;
}
抛出新错误(errMsg);
}
我不知道如何修改该页面,使其使用我的母版页

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


谢谢

这真的很容易。。。只需将XAP文件作为另一个Flash或任何其他第三方控件,您想要在您的页面…< /P> 只需创建一个WebContentForm,从任何母版页继承它,然后按照下面关于如何在aspx页面中集成SL的文章中的链接进行操作

以下是有关如何以各种方式集成XAP的详细信息:


问候。

这是你的建议吗

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

然而,上面由VS2010生成的页面在同一项目中运行良好

试试看。应该很近。其思想是将样式和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> 

现在回答已经太晚了,但可能对其他正在寻找答案的人有所帮助

所有JavaScript代码都会转到标题占位符,并且在前面由DaveB声明

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

并避免使用
width=“100%”
height=“250%”
,因为Firefox不会呈现Silverlight内容

<asp:Content ID="Content1" ContentPlaceHolderID="MySiteMasterHeaderPlaceholder" Runat="Server">
    // JavaScript code goes here
</asp: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>