【发布时间】:2020-02-21 15:15:04
【问题描述】:
我在我的项目中使用FFImageLoading 而不是Image 以获得更高级的功能,例如占位符。在我的项目中,有一个需要显示的图像列表。所以我也使用列表视图。
<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 属性加载图像。
【问题讨论】:
-
您不能将
CacheDuration属性设置为0 或-1 之类的吗? -
让我检查一下,已经用 0 试过了,但到目前为止没有运气
-
@GeraldVersluis 0 & -1 不起作用
-
当我再次重新启动应用程序时,图像似乎更新了。
-
难道你不能通过你的图像“foreach”并使缓存无效吗?在后台任务中弹出它,这样你就不会阻塞主 UI。
标签: listview caching xamarin.forms ffimageloading