listview - 如何清除/避免 FFImageLoading 在列表项图像中的缓存

标签 listview caching xamarin.forms ffimageloading

我正在使用 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/

相关文章:

node.js - 使用 Redis 缓存 mongoose 对象

ms-access - Access 2013 中的 VB 脚本在 QuickBooks Enterprise 14 中产生 "out of memory"错误

xaml - Xamarin ICommand无法启动

delphi - 如何在 ListView 中显示文本文件中的数据?

qt - QML 如何获取 ListView 中的当前元素索引?

c# - 如何使用触摸将元素拖出可滚动的 ListView,而无需按住元素 [UWP]

c - 如何优化缓存性能?

c# - 如何在 MVVM 架构中将 animationview play 与 LottieForms 绑定(bind)?

xamarin - 如何更改 Xamarin.Forms 上的后退按钮文本

c# - mvvm 如何使 ListView 自动滚动到 ListView 中的新项目