2010-03-27 80 views
2

我有一個Silverlight應用程序必須動態加載圖像,具體取決於圖像名稱。現在即時通訊採取正確的方法是通過查詢字符串傳遞圖像名稱的頁面,並將其作爲一個參數去Silverlight的客體標籤在Silverlight上動態加載圖像

這是傳遞

Response.Redirect("Build.aspx?img=" + this.PictureUploader.PostedFile.FileName; 

查詢字符串,我試着在名稱=形象價值的最後一個參數標記

<object id="SilverlightObject" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> 
     <param name="source" value="Silverlight/iMapsSL.xap"/> 
     <param name="onError" value="onSilverlightError" /> 
     <param name="background" value="white" /> 
     <param name="minRuntimeVersion" value="3.0.40624.0" /> 
     <param name="autoUpgrade" value="true" /> 
     <param name="image" value="<%# Request.QueryString["img"] %>" /> 
     <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> 

= Requerst.QueryString

我趕上了圖像內:它傳遞給Silverlight的這樣Silverlight應用程序像這樣

private void Application_Startup(object sender, StartupEventArgs e) 
    { 
     string pictureName = ""; 

     if (e.InitParams != null && e.InitParams.Count > 0) 
     { 
      pictureName = e.InitParams["image"]; 

      this.RootVisual = new MainPage(pictureName); 
     } 

     else 
     { 
      this.RootVisual = new MainPage(); 
     } 
    } 

而開始的MainPage的時候,我設置的圖像控制的這樣

this.Image.Source = new BitmapImage(new Uri(pictureName, UriKind.RelativeOrAbsolute)); 

但Silverlight中加載圖像源沒有圖像,任何幫助別人?

回答

1

您不能通過創建像「image」這樣的參數名來設置任意值。通過指定「initparams」參數來創建InitParams。 「initparams」值是以逗號分隔的一組name = value對。因此,您的代碼應如下所示: -

<object id="SilverlightObject" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> 
     <param name="source" value="Silverlight/iMapsSL.xap"/> 
     <param name="onError" value="onSilverlightError" /> 
     <param name="background" value="white" /> 
     <param name="minRuntimeVersion" value="3.0.40624.0" /> 
     <param name="autoUpgrade" value="true" /> 
     <param name="initparams" value="image=<%# Request.QueryString["img"] %>" /> 
     <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>