简体   繁体   中英

ImageCell not showing image from drawable

Hello and apologies if I break any customs, it is my first time asking here.

I am attempting to create a ListView with an ItemSource of an ObservableCollection<Opinion> and composed of an ImageCell.

Opinion is a class with a method that determines which of the five pictures inside drawable becomes the source for said image.

This is the Opinion class code:

public class Opinion
    {
        public string User { get; set; }
        public string Declaration { get; set; }
        public int Rating { get; set; }

        public string RatingSource;

        public Opinion() { }
        public Opinion(string user, string declaration, int rating)
        {
            this.User = user;
            this.Declaration = declaration;
            this.Rating = rating;
            this.RatingSource = getRating(rating);
        }

        private string getRating(int rating)
        {
            switch (rating)
            {
                case 1:
                    return ("OneStar.png");
                case 2:
                    return ("TwoStar.png");
                case 3:
                    return ("ThreeStar.png");
                case 4:
                    return ("FourStar.png");
                case 5:
                    return ("FiveStar.png");
                default:
                    return ("");
            }
        }
    }
}

The XAML for the ListView:

<ContentPage Title="Oponions">
        <StackLayout>
            <ListView x:Name="OpinionsView" ItemsSource="{Binding opi}" HasUnevenRows="True" IsEnabled="False">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ImageCell ImageSource="{Binding RatingSource}" 
                               Text="{Binding Declaration}" 
                               TextColor="AntiqueWhite" 
                               Detail="{Binding User}" 
                               DetailColor="LightGray" />
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage>

And the C# code for it:

namespace Interfaces23
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class DeepArticle : TabbedPage
    {
        ObservableCollection<Opinion> opi { get; set; } = new ObservableCollection<Opinion>();
        public DeepArticle(Article articulo)
        {
            InitializeComponent();

            opi = articulo.Opinions;
            OpinionsView.ItemsSource = opi;

            lbDescription.Text = articulo.Description;
            lbPrecio.Text = "Precio: " + articulo.Price;
            Image img = new Image();

            lbPrueba.Text = articulo.Opinions[0].RatingSource;
        }
    }
}

Every Binding works as it should and shows the information properly, except for the image. As far as I understand, RatingSource should return "FiveStar.png" as a string, which should then act as the value for ImageSource inside the ImageCell, but I must be missing something.

Nevermind, I'm just an idiot. Forgot the {get; set;} for RatingSource.

I'll leave this here just in case someone has the same problem and the same idiotic solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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