Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image from WPF project's resource stopped showing

Tags:

c#

wpf

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.

like image 503
Thiago Rosa Avatar asked Sep 02 '25 14:09

Thiago Rosa


1 Answers

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"/>
like image 150
Thiago Rosa Avatar answered Sep 05 '25 03:09

Thiago Rosa