John
John

Reputation: 3945

how to display an image on xamarin forms using binding tag from image

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

Upvotes: 0

Views: 231

Answers (1)

Jason
Jason

Reputation: 89204

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;

Upvotes: 2

Related Questions