简体   繁体   English

Xamarin.Forms ImageCell 不显示图像版本 4.7.0.xx

[英]Xamarin.Forms ImageCell not displaying image version 4.7.0.xx

I already tried, string to ImageSource in my model but still I did not get image to display in ImageCell.我已经尝试过,在我的 model 中将string连接到ImageSource ,但我仍然没有在 ImageCell 中显示图像。

If I try this line of code <Image Source="https://img.icons8.com/carbon-copy/2x/user.png"></Image> , image displays fine.如果我尝试这行代码<Image Source="https://img.icons8.com/carbon-copy/2x/user.png"></Image> ,图像显示正常。

Model Model

public class Contact
{
    public string Name { get; set; }
    public string Status { get; set; }
    public ImageSource ImageUri { get; set; }
}

XAML: XAML:

    <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="App1.ListPage">
    <ContentPage.Content>
        <StackLayout>
            <ListView x:Name="listView" SeparatorVisibility="Default" SeparatorColor="Blue">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <!--<TextCell Text="{Binding Name}" Detail="{Binding Status}" TextColor="Accent" DetailColor="Beige"></TextCell>-->
                        <!--<TextCell Text="{Binding Name}" Detail="{Binding Status}"></TextCell>-->
                        `<ImageCell Text="{Binding Name}" Detail="{Binding Status}" ImageSource="{Binding ImageUri}`"></ImageCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <!--<Image Source="https://img.icons8.com/carbon-copy/2x/user.png"></Image>-->
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

XAML.cs XAML.cs

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListPage : ContentPage
{
    public ListPage()
    {
        InitializeComponent();

        listView.ItemsSource = new List<Contact>
        {
            new Contact{ Name="Monkey D. Luffy", ImageUri=ImageSource.FromUri(new Uri("https://img.icons8.com/carbon-copy/2x/user.png"))},
            new Contact{ Name="Monkey D. Dragon",
                ImageUri=ImageSource.FromUri(new Uri("https://img.icons8.com/carbon-copy/2x/user.png"))},
            new Contact{ Name="Portgas D. Ace",
                ImageUri=ImageSource.FromUri(new Uri("https://img.icons8.com/carbon-copy/2x/user.png")), Status="Hello World!"}
        };
    }
}

just did two tests on my playground.刚刚在我的操场上做了两次测试。

I kicked off with a blank Xamarin.Forms project (only one MainPage there) in VS2019, then我从 VS2019 中的一个空白 Xamarin.Forms 项目(那里只有一个 MainPage)开始,然后

  1. updated the XF nuget package to 4.7.0.1142.将 XF nuget package 更新为 4.7.0.1142。
  2. pasted your code.粘贴您的代码。
  3. remove two extra ` characters in your xaml code snippet.在 xaml 代码段中删除两个额外的`字符。

It's working.它正在工作。

Then, I tried the string property in the model class like this:然后,我尝试了 model class 中的字符串属性,如下所示:
public string ImageUri { get; set; }
And also set string value in xaml.cs class like this:并在 xaml.cs class 中设置字符串值,如下所示:
new Contact{ Name="", ImageUri="https://xxx.png"}

在此处输入图像描述

It's also working.它也在工作。

Not sure about the issue, but your code is fine anyway.不确定这个问题,但无论如何你的代码都很好。

Try to use this nuget https://github.com/luberda-molinet/FFImageLoading for images.尝试将此 nuget https://github.com/luberda-molinet/FFImageLoading用于图像。 Is the best !!是最好的 !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM