简体   繁体   中英

How to make transparent background of Silverlight 3 application?

How to make transparent background of Silverlight 3 application? I have the next code but it does not work (

          <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>

You've got a partially-transparent background there at the moment (#80FF0000). Why not change it to fully transparent like this:

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

You can then draw whatever you want to be partially-transparent in your Silverlight app. However, be warned that transparent background with windowsless=true can be REALLY slow. It's better to avoid this using clever graphic design to fit the Silverlight control into the page, if possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM