Bengi Besceli
Bengi Besceli

Reputation: 3748

Image in Xamarin

The image is not showing with the below code in Xamarin. Its in images folder.

var image = new Image { Aspect = Aspect.AspectFit };
image.Source = "images/image1.png";
Content = image;

How can I fix this ?

Note : I'm using a Forms application.

Upvotes: 0

Views: 419

Answers (1)

Joehl
Joehl

Reputation: 3701

You have to place the images in the right folder of each platform-project.

  • iOS - Place images in the Resources folder with Build Action: BundleResource
  • Android - Place images in the Resources/drawable directory with Build Action: AndroidResource.
  • Windows Phone / Windows / UWP - Place images in the application's root directory with Build Action: Content

You can find more Infos here.

Edit (images in PCL-project)

To embed an image in a project, right-click to add new items and select the image/s you wish to add. By default the image will have Build Action: None; this needs to be set to Build Action: EmbeddedResource.

And then load the Image FromResource(..):

var embeddedImage = new Image { Aspect = Aspect.AspectFit };
embeddedImage.Source = ImageSource.FromResource("test.jpg");

To load images from the PCL-Project -> look at this page.

Upvotes: 1

Related Questions