我正在使用 FFImageLoading而不是我项目中的 Image
以获得占位符等更高级的功能。在我的项目中,有一个需要显示的图像列表。所以我正在使用 ListView 。
<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 清除单个 ImageView 的缓存
await CachedImage.InvalidateCache(Image.Source, CacheType.All, true);
但是在ListView中如何实现呢?我正在使用 Binding 属性在此处加载图像。
最佳答案
经过一段时间后,我已经解决了我的问题。最后很简单。
在我的 ListView 的绑定(bind)模型类中,当设置 imageUrl
时,我只是同时清除了该 url 的缓存。
private string mImageUrl { get; set; }
public string imageUrl
{
get{
return mImageUrl;
};
set{
mImageUrl = value;
await CachedImage.InvalidateCache(mImageUrl, CacheType.All, true);
};
}
这将清除以该 imageUrl 作为键的缓存图像。 谢谢大家的支持。快乐编码:)
关于listview - 如何清除/避免 FFImageLoading 在列表项图像中的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44562219/