2009-11-09 75 views
0

如何製作Silverlight 3應用程序的透明背景?我有一個代碼,但它不工作(如何製作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> 

回答

2

你得的那一刻(#80FF0000)部分透明的背景有爲什麼不將其更改爲完全透明是這樣的:

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

然後,您可以在Silverlight應用程序中繪製任何想要部分透明的內容,但應注意,透明背景與windowsless = true可能會非常緩慢。最好避免使用巧妙的圖形設計來適應Silverlight控件進入頁面,如果可能的話。

+0

但它沒有與谷歌瀏覽器一起工作!( – Rella 2009-11-10 15:14:14