Xamarin Forms 5 - 下载图片以备将来使用

问题描述

对于我的应用程序,我有一个对象列表视图,其中一些对象持有一个指向我们服务器上图像的 URL。无论在任何情况下,此图像都必须可用。

用户单击其中一个 ListView-Item 时,他导航到包含此对象信息的 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 上。

图像似乎是随机加载或未加载。有时它们在打开页面后出现,有时它们已经存在,当页面出现时。有时,即使在 DownloadOnly 和 Preload 周围存在 try/catch 子句,它们也不存在于 ImageView 中,并且应用程序崩溃而不会显示任何错误

尽管 DownloadOnly 和 PreloadOnly 在页面甚至可以打开之前被调用 - 即在应用程序的启动过程中。使用这两种方法之一时会出现此行为。

我想知道我是否遗漏了有关如何使用这两种方法内容,但是我在其他地方发现的有关 FFImageLoading 的内容对我没有帮助。行为不断出现。

也许有更好的方法

谢谢大家:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)