0

Using xamarin forms trying to display an image using binding...followed a few online Q's already including the answer on this one https://stackoverflow.com/questions/30850510/how-to-correctly-use-the-image-source-property-with-xamarin-forms just cant seem to get the image to display...yes I knoW I can load the image by using <Image Source="Bud.jpeg"></Image> which works fine....but I would like to display it using binding....

eg..

xaml
 <Image Source="{Binding imageTest}"></Image>


code

            var imageTest = new Image { Aspect = Aspect.AspectFit };
            imageTest.Source = ImageSource.FromFile("Guinness.jpg");

anyone any idea why? thanks

John
  • 3,965
  • 21
  • 77
  • 163

1 Answers1

2

You can only bind to public properties

<Image Source="{Binding imageTest}" /> 

then declare a public property in your code-behind

public string imageTest { get; set; }

and then set the property value and BindingContext

imageTest = "Guinness.jpg";
this.BindingContext = this;
Jason
  • 86,222
  • 15
  • 131
  • 146