xamarin - Xamarin Forms 5 - 下载图像以供将来使用
问题描述
对于我的应用程序,我有一个对象列表视图,其中一些对象持有一个指向我们服务器上图像的 url。无论如何,此图像必须 - 在任何情况下 - 可用。
当用户单击其中一个 ListView-Items 时,他导航到包含此对象信息的 ContentPage。包括一个包含该图像的 ImageView。
该页面的 XAML 如下所示:
IsVisible="False">
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" NumberOfTapsRequired="1" />
</Grid.GestureRecognizers>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<forms:CachedImage x:Name="gridImageControl"
Grid.Row="0" Margin="10"
CacheType="All"
BindingContext="{Binding theObject}"
VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"
Source="{Binding TheUrl}"
Aspect="AspectFill"
DownsampleToViewSize="False"
LoadingPlaceholder="{fa:ImageResource thenamespace.Images.langlogo.png}"
ErrorPlaceholder="{fa:ImageResource thenamespace.Images.errorplaceholder.png}"
RetryCount= "3" RetryDelay= "600" />
<StackLayout>
<Image HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Aspect="AspectFill" >
<Image.Source>
<FontImageSource FontFamily="faSolid" Glyph="{x:Static fa:FontAwesomeIcons.SearchPlus}"
Color="Black" Size="50">
</FontImageSource>
</Image.Source>
</Image>
<Label x:Name="ClickOnMeLabel" Style="{DynamicResource label_base_text_style}" FontAttributes="Bold"
Text="Klicke zum Betrachten" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="Large" TextColor="Black">
</Label>
</StackLayout>
</Grid>
无法将图像包含在应用程序包中,因为图像由我们平台的管理员用户上传并下载到与该管理员用户关联的所有用户设备。
我尝试使用 FFImageLoading 的 CachedImage 和ImageService.Instance.LoadURL("THEURL").WithCache(CacheType.All).DownloadOnlyAsync()
也
ImageService.Instance.LoadURL("THEURL").WithCache(CacheType.All).PreloadAsync()
两者都会导致应用程序出现奇怪的行为,尤其是在 iOS 上。
图像似乎是随机加载或未加载的。有时它们在打开页面后出现,有时它们在页面出现时已经存在。有时,它们不会出现在 ImageView 中,并且即使在 DownloadOnly 和 Preload 周围有一个 try/catch 子句,也会使应用程序崩溃而不会显示任何错误。
尽管在页面甚至可以打开之前调用了 DownloadOnly 和 PreloadOnly - 即在应用程序的启动过程中。使用这两种方法中的任何一种时都会出现此行为。
我想知道我是否错过了有关如何使用这两种方法的一些信息,但是我在其他地方发现的关于 FFImageLoading 的内容并没有帮助我。行为不断出现。
也许有更好的方法?
谢谢你们 :)
解决方案
推荐阅读
- sql - 如何获得两个日期的四舍五入差 SQL Server
- angular - 从 JSON 响应生成 Angular 组件所需的新格式
- snowflake-cloud-data-platform - 在雪花中检索帐户的所有可用屏蔽策略
- flutter - 颤振:firebase_admob 与 admob_flutter
- java - 所有用户都可以使用 azure spring security 登录
- java - 使用仅使用单个代码行的表示法将多个元素分配给数组的时间复杂度是多少?
- javascript - 任何人都可以告诉我的 hbs Templete 没有运行的快递错误在哪里?
- python - 在 python 脚本调用中传递文件的位置而不是变量
- angular - 如何在 ngOnit 方法中为订阅者和超时编写测试用例?
- php - 使用php和html上传单个文本文件并遍历查找重复的单词