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

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.