Image in List

Daryl V 41 Reputation points
2021-10-03T18:20:06.657+00:00

Hello,

I am trying to include images in my list that will be bound to the page. The intent is when the user hits next on the interface the new image will come on with the new text. The images are embeded and are in their own image folder. I have included ImageA (line 27) as the marker for the image I am trying to include but it is not working:

public class ClassA
    {
        public string TitleText { get; internal set; }
        public string EngText { get; internal set; }
        public string ItText { get; internal set; }
        public string PageNo { get; internal set; }
        public string ImageA { get; internal set; }
    }

    public partial class ClassB : ContentPage
    {
        List<ClassA> ClassA { get; set; }
        int ndx = 0;

        public ClassB()
        {
            InitializeComponent();

            ClassA = new List<ClassA>
            {
                new ClassA
                {
                    TitleText = "Title Text",
                    EngText = "ENGtext",
                    ItText = "ITtext",
                    PageNo = "1/4",
                    ImageA = "local:ImageResource Project.Images.ClassB.Image.png"
                },

Many thanks for your help,

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
{count} votes

Accepted answer
  1. Kyle Wang 5,531 Reputation points
    2021-10-04T05:25:27.523+00:00

    Hi DarylV,

    Welcome to our Microsoft Q&A platform!

    According to the documentation: Xamarin.Forms Basic Bindings, we know that the Binding is followed by a property. So you can't add a "local:ImageResource" string after Binding.

    As a workaround, you can set the image resource as follows.
    xaml

    <Image x:Name="MyImage" />  
    

    xaml.cs

    MyImage.Source = ImageSource.FromResource("WorkingWithImages.beach.jpg", typeof(EmbeddedImagesXaml).GetTypeInfo().Assembly);  
    

    Regards,
    Kyle


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful