2017-06-15 78 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作为关键字的缓存图像。 谢谢大家的支持。快乐编码:)