How to load specific xaml file from a xap file?

不问归期 提交于 2019-12-11 07:30:00

问题


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


来源:https://stackoverflow.com/questions/6009898/how-to-load-specific-xaml-file-from-a-xap-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!