2014-02-06 67 views
0

我在WP8上有應用程序,它包含從服務器加載的圖像。圖片在服務器上發生變化,但具有相同的名稱和相同的網址。更改後,手機仍會顯示以前的圖片。如何解決這個問題呢。刷新圖像同名

回答

0

這是由於內置資源緩存,這會影響遠程請求以及在您的應用程序中對本地圖像資源的請求。在聲明圖像控件標記時,可以通過手動創建其源屬性來禁用緩存。例如:

<Image> 
    <Image.Source> 
     <BitmapImage UriSource="{Binding ContentPath}" 
        CreateOptions="IgnoreImageCache" /> 
    </Image.Source> 
</Image> 
+0

我試過沒有工作 – user3280075

0

那麼,手機會緩存下載的圖像。如果你想設置一個新的圖像,你必須「清理」圖像源。你的問題是不是給我inave信息,但是從我的理解,一個簡單的轉換應該做的伎倆:

public class CacheImageConverter : IValueConverter 
    {  
     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      string path = value as string; 
      Uri imageFileUri = new Uri(path, UriKind.Absolute); 
      BitmapImage bm = new BitmapImage(imageFileUri); 
      return bm; 
      } 

     public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      throw new NotImplementedException(); 
     } 
    } 

XML

<phone:PhoneApplicationPage.Resources> 
    <imgConv:CacheImageConverter x:Key="ConvertNew" /> 
</phone:PhoneApplicationPage.Resources> 

...

<Image Source="{Binding strPath, Converter={StaticResource ConvertNew}}"/> 
+0

這並沒有完成任何事情。問題是由於緩存並向同一個URL發出請求。 Web服務器需要發佈更多信息緩存指令,或者手機需要忽略緩存。該代碼仍然會輸出緩存的圖片資源。 – lsuarez

+0

我的想法是創建新的實例,我相信它會工作 –

+1

.htaccess/expires標題解決了問題 – user3280075