首页 文章

Xamarin:FFImageLoading没有在iOS上使用内部列表视图显示

提问于
浏览
0

我目前在自定义数据模板中的listView上使用FFImageLoading库 .

<ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.ContextActions>
                                <MenuItem Clicked="OnDelete" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
                            </ViewCell.ContextActions>
                            <StackLayout
                                Padding="12,10,12,10" 
                                BackgroundColor="Transparent"
                                Orientation="Horizontal">
                                <Image
                                    DownsampleToViewSize="true"
                                    Aspect="AspectFit"
                                    Source="{Binding FileThumbnail, Converter={StaticResource mimeTypeToImageConverter}}"
                                    WidthRequest="60"
                                    HeightRequest="60">
                                </Image>

在mimeTypeToImageConverter里面:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is string)
        {
            var file = (string)value;     

            if (FileUtilities.IsImageType(file))
            {
                //var fileImageSource = new FileImageSource();
                //fileImageSource.File = file;
                var imageSource = ImageSource.FromFile(file);
                return imageSource;
            } 
            else {
                return ImageSource.FromFile("ic_file_white.png");
            }

        } 
        return null;
    }

我在android上使用但是android工作得很好 . 当我改回图像控件时,iOS将显示图像 .

我真的需要它来减小图像大小 . 你们之前有没有遇到过这个问题 .

2 回答

  • 2

    您需要使用FFImageLoading控件,而不是使用图像控件

    更改

    <Image>...</Image>
    

    <forms:CachedImage>...</forms:CachedImage>
    

    还要添加命名空间

    <ContentPage xmlns:forms="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms">
    

    CachedImage应具有与Image相同的所有属性

    哎呀忘了提,你需要添加DownsampleHeight或DownsampleWidth来减小尺寸 .

  • 0

    正在尝试通过http下载图像,而不是https?

    您需要在info.plist中添加以下内容

    <key>NSAppTransportSecurity</key>
    <dict>
      <!--Include to allow all connections (DANGER)-->
      <key>NSAllowsArbitraryLoads</key>
          <true/>
    </dict>
    

相关问题