Ale*_*lan 2 listview caching xamarin.forms ffimageloading
我正在使用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>
Run Code Online (Sandbox Code Playgroud)
我的问题是我不想在这里使用缓存技术,因为我的服务器图像可能会在不更改 URL 的情况下更改。
我知道如何使用 FFImageLoading 清除单个图像视图的缓存
await CachedImage.InvalidateCache(Image.Source, CacheType.All, true);
Run Code Online (Sandbox Code Playgroud)
但是如何在 ListView 中实现这一点呢?我在这里使用 Binding 属性加载图像。
经过一段时间的努力,我已经解决了我的问题。最后它非常简单。在我的列表视图的绑定模型类中,在设置imageUrl我刚刚使用该 url 同时清除缓存时。
private string mImageUrl { get; set; }
public string imageUrl
{
get{
return mImageUrl;
};
set{
mImageUrl = value;
await CachedImage.InvalidateCache(mImageUrl, CacheType.All, true);
};
}
Run Code Online (Sandbox Code Playgroud)
这将清除以该 imageUrl 为键的缓存图像。谢谢大家的支持。快乐编码:)
| 归档时间: |
|
| 查看次数: |
2290 次 |
| 最近记录: |