Completely embedding a Silverlight Application in an HTML Page?

隐身守侯 提交于 2019-12-25 02:52:28

问题


I am still trying to solve the issue of displaying an image on a website without having the image external. As the data: scheme does not work on older browsers or big images, I'm currently experimenting with Silverlight.

I managed to solve the embedding by Base64 Encoding the Image and passing it in using the InitParams, but actually I just moved my problem away: Instead of an external Image, I now have an external XAP File...

Is there a way taking the XAP File and somehow embedding it in the HTML? Or alternatively, can I use the JavaScript-based Silverlight 1.1 in this situation? It's literally just displaying an image that has been passed in as a String.


回答1:


For what you're trying to do, it sounds like you might want to look at Sam Ruby's SVG with XAML fallback, which displays SVG in browsers which support it, and renders via Silverlight in IE.

You can inline XAML like this (source: MSDN):

    <html>
    <head>
      <title>Display Date</title>
      <!-- Define Loaded event handler for TextBlock. -->
      <script type="text/javascript">
        function setDate(sender, eventArgs)
        {
          sender.text = Date();
        }
      </script>
    </head>

    <body bgcolor="Teal">

    <!-- Define XAML content. -->
    <script type="text/xaml" id="xamlContent"><?xml version="1.0"?>
      <Canvas
        xmlns="http://schemas.microsoft.com/client/2007"
        Background="Wheat">
        <TextBlock
          Canvas.Left="20"
          FontSize="24"
          Loaded="setDate" />
      </Canvas>
    </script>

    <div id="silverlightControlHost">
      <object type="application/x-silverlight" width="100%" height="100%" id="slc">
        <param name="source" value="#xamlContent"/>
        <param name="onload" value="onLoaded" />
        <param name="iswindowless" value="true" />
      </object>
      <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
    </div>
    </body>
    </html>

Note that Firefox 2 had a bug (bugzilla 356095) which prevented using this with XHTML DOCTYPE. I believe this may be fixed.



来源:https://stackoverflow.com/questions/1223166/completely-embedding-a-silverlight-application-in-an-html-page

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