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")
Asked
Active
Viewed 370 times
0

Null Reference Exception
- 232
- 4
- 9
-
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 Answers
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
-
-
Btw when I insert your code, Visual Studio Said Blend do not support this file format – Null Reference Exception Apr 28 '18 at 13:08
-
Made changes to my answer. Added WPF solution - have a look if that works for you – Mikolaj Kieres Apr 29 '18 at 00:34
-
Assume I Need a Image called Logo.png The directory point to F:\Resources\Logo.png but I need F:\MySolution\MyProject\bin\Debug\Reources\Logo.png. And the Program is In F:\MySolution\MyProject\bin\Debug\ – Null Reference Exception Apr 29 '18 at 02:01
-
I don't think I understand. You want to reference an image that is included in your project or an image that is somewhere on the local hard drive? – Mikolaj Kieres Apr 29 '18 at 02:22