How to load specific xaml file from a xap file?

2019-08-04 06:08发布

问题:

I have the following page that references my silverlight application file. This works fine. I was wondering if, instead, I could point to a specific xaml file that is in the .xap file?

Perhaps something like /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>

Thanks!

回答1:

First of all see my answer here to a very similar request that does most of what you need.

All you now need is to get the xaml file name from the query string to the initparams. Your existing code would become:-

            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]%>'
        );