如何制作Silverlight 3应用程序的透明背景?

时间:2009-11-09 23:03:26

标签: c# html silverlight-3.0 background transparency

如何制作Silverlight 3应用程序的透明背景?我有下一个代码,但它不起作用(

          <html xmlns="http://www.w3.org/1999/xhtml" >
          <!-- saved from url=(0014)about:internet -->
          <head>
<title>BGtest</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">
    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>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head>
          <body bgcolor="#00FF00">
<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="BGtest.xap"/>
      <param name="onError" value="onSilverlightError" />
                     <param name="pluginbackground" value="Transparent" /> 
                <param name="background" value="#80FF0000"/>
                     <param name="windowless" value="true" />  
      <param name="minRuntimeVersion" value="3.0.40624.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=108181" 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>

1 个答案:

答案 0 :(得分:2)

目前你有一个部分透明的背景(#80FF0000)。为什么不将它改为完全透明,如下所示:

<param name="background" value="transparent"/>

然后,您可以在Silverlight应用中绘制想要部分透明的内容。但是,请注意,使用windowsless = true的透明背景可能非常慢。如果可能的话,最好使用巧妙的图形设计来避免这种情况,以使Silverlight控件适合页面。