0

Sorry for bad describe in the title. I have a image in "C:\Users\aUser\Desktop\Program\Image\Image.png" But my program is in the same folder with the Image. I can set the Directory manually <Image Source="C:\Users\aUser\Desktop\Program\Image.png" But when the parent directory is moved, the code will no longer work. So how can I set the Source of the image that in the child folder without use of the code behind Image.Source = new BitmapSource(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"\Image\Image.png") Image

  • I can see that you've updated your question. I'm not sure how you're getting that image (i.e. Logo.png) into the `Resources` folder, so please make sure that you follow [these steps](https://stackoverflow.com/a/25714375/510627) to add the image to your project solution and reference it as per my answer – Mikolaj Kieres Apr 30 '18 at 22:35
  • Anyway, I add Logo.png in code-behind – Null Reference Exception May 01 '18 at 02:38

1 Answers1

0

You will need to be more specific what XAML 'version' you are using (e.g. WPF, UWP or Xamarin.Forms). Anyways, here goes:

UWP

You should read through these docs. Your XAML code could look like this:

<Image Source="ms-appx:///Assets/Image.png"/>

Where Assets/Image.png is a path to your image

Xamarin.Forms

Have a look at these docs. The solution depends on the platform

WPF

Have a look at these docs. Your XAML code could look like this:

<Image>
    <Image.Source>
        <BitmapImage UriSource="/Images/image.png" />
    </Image.Source>
</Image>
Mikolaj Kieres
  • 4,137
  • 1
  • 20
  • 23