首页 > 解决方案 > 来自 URL 的 Xamarin Forms 图像源被缓存?

问题描述

我的 FTP 服务器上有一些要显示的图像,我在 XAML 中的代码是:

 <Image x:Name="sponsor1" Source="http://website.com/web/image1.png" WidthRequest="50" HeightRequest="50" HorizontalOptions="CenterAndExpand"/>

我最近更改了 FTP 服务器上的图像,但我的应用程序(通过 USB 连接并且应用程序由 IDE 运行)仍在显示不再存在的旧图像。

为什么这样做?是缓存吗?如何禁用它?

标签: imagecachingxamarin.forms

解决方案


是的,默认情况下启用缓存。要禁用,请设置CachingEnabled="false"

<Image 
    HorizontalOptions="CenterAndExpand"
    VerticalOptions ="CenterAndExpand">
    <Image.Source>
        <UriImageSource Uri="{Binding Image}" 
            CacheValidity="14" 
            CachingEnabled="true"/>
    </Image.Source>
</Image>

推荐阅读