Home > Mobile >  How to write Source for image from Resources/Images subfolder
How to write Source for image from Resources/Images subfolder

Time:11-17

I have two PNG-files: Resoucres/Images/image1.png and Resoucres/Images/subfolder/image2.png so, I want to set they as Source for Image:

when I set 1st image: <Image ... Source="image1.png" /> all working correctly, but when I try to set 2nd image:

<Image ... Source="subfolder.image2.png" /> image isn't displaying.

So, how I need to write the path of the 2nd image?

CodePudding user response:

An image can be added to your app project by dragging it into the Resources\Images folder of the project, where its build action will automatically be set to MauiImage.

Images can also be added to other folders of your app project. However, in this scenario their build action must be manually set to MauiImage in the Properties window.

So you can right click the image2.png file select the properties then change the Build Action to MauiImage and you can use the image directly.

<Image ... Source="image2.png" />
  • Related