I added some images as resources to my WPF project, changed their Build Action to Resource
in Solution Explorer and added them to my Main Window like this:
<Image ... Source="Resources/user.png"/>
Everything was working until I added and removed one project from my solution, then these images stopped showing both in design and runtime. The <Image Source/>
tag in XAML editor and the Error List now show the message:
Could not find a part of the path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Resources\user.png".
I tried restarting Visual Studio and the computer, and also cleaned and rebuilt it, but I still don't get the images.
When you use <Image Source="" />
, the Source
is relative to the XAML file path. The XAML file was on the root, and I moved it to a View
folder. I didn't know about this until I read this comment.
The images are stored in a Resources
folder inside the project, so in this case the Source
property must start with a forward slash to point it to root, like this:
<Image ... Source="/Resources/user.png"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With