如何从xap文件加载特定的xaml文件?

时间:2011-05-15 17:04:53

标签: asp.net silverlight silverlight-4.0

我有以下页面引用了我的silverlight应用程序文件。这很好用。我想知道是否可以指向.xap文件中的特定xaml文件?

也许像/ClientBin/test.xap?File=SomeXaml.xaml

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test.Web.WebForm1" %>

<!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></title>
    <script type="text/javascript" src="Silverlight.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="silverlightControlHost">
        <script type="text/javascript"> 
            Silverlight.createObject(
            "ClientBin/test.xap",  // source
             document.getElementById('silverlightControlHost'),  // parent element
            "someId",  // id for generated object element
            {
            width: "600px",
            height: "600px",
            background: "blue",
            version: "4.0.60310.0",
            autoUpgrade: "true"
        },
            { onError: null }, null
        );
        </script>
    </div>
    </form>
</body>
</html>

谢谢!

1 个答案:

答案 0 :(得分:3)

首先,我的回答here是一个非常类似的请求,可以满足您的大部分需求。

您现在需要的是从查询字符串中获取xaml文件名到initparams。您现有的代码将变为: -

            Silverlight.createObject(
            "ClientBin/test.xap",  // source
             document.getElementById('silverlightControlHost'),  // parent element
            "someId",  // id for generated object element
            {
            width: "600px",
            height: "600px",
            background: "blue",
            version: "4.0.60310.0",
            autoUpgrade: "true"
        },
            { onError: null }, 'StartupPage=<%=Request.QueryString[File]%>'
        );