2017-06-15 72 views
1

我在我的項目中使用FFImageLoading而不是Image以獲取更多高級功能,如佔位符。在我的項目中,有一個需要顯示的圖像列表。所以我使用相同的列表視圖。如何清除/避免緩存列表項目圖像 - Xamain.Forms

<ListView x:Name="membersList" ItemTapped="Handle_ItemTappedMember" HorizontalOptions="FillAndExpand" HasUnevenRows="true" SeparatorVisibility="None" BackgroundColor="#EEEEEE" Grid.Row="0" Grid.Column="0"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <ViewCell> 
         <ViewCell.View> 
          <StackLayout Orientation="Horizontal" Padding="5,5,5,5" HeightRequest="75" Margin="10,5,10,5" BackgroundColor="White" HorizontalOptions="FillAndExpand"> 
           <ffimageloading:CachedImage Source="{Binding imageUrl}" x:Name="patImage" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" VerticalOptions="Center"> 
            <ffimageloading:CachedImage.Transformations> 
             <fftransformations:CircleTransformation /> 
            </ffimageloading:CachedImage.Transformations> 
           </ffimageloading:CachedImage> 
           <StackLayout Spacing="3" Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand"> 
            <Label FontAttributes="Bold" FontSize="14" TextColor="#212121" Text="{Binding FullName}" /> 
            <Label FontSize="12" TextColor="#212121" Text="{Binding Relation}" /> 
            <Label FontSize="12" TextColor="#212121" Text="{Binding Pat_ID}" /> 
           </StackLayout> 
          </StackLayout> 
         </ViewCell.View> 
        </ViewCell> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
     </ListView> 

我的問題是我不想在這裏使用緩存技術,因爲我的服務器映像可能會更改而不更改URL。

我知道如何清除單個圖像視圖的緩存與FFImageLoading

await CachedImage.InvalidateCache(Image.Source, CacheType.All, true); 

但如何在ListView控件來實現這一目標?我正在使用Binding屬性在這裏加載圖像。

+0

難道你不能只將'CacheDuration'屬性設置爲0或-1或其他? –

+0

讓我檢查一下,已經嘗試過0,但到目前爲止沒有運氣 –

+0

@GeraldVersluis 0&-1不能正常工作 –

回答

1

經過一段時間的花費,我清除了我的問題。最後它非常簡單。 在我的listview的綁定模型類中,當設置imageUrl時,我只是同時使用該url清除了緩存。

private string mImageUrl { get; set; } 
public string imageUrl 
{ 
get{ 
    return mImageUrl; 
    }; 
set{ 
    mImageUrl = value; 
    await CachedImage.InvalidateCache(mImageUrl, CacheType.All, true); 
    }; 
} 

這將清除該imageUrl作爲關鍵字的緩存圖像。 謝謝大家的支持。快樂編碼:)