I\'m currently working w/ VS studio 2010, .NET 4.0. Here is my scenario:
I currently have a class library project called \"Images\" that contains a sub folder calle
Maybe this helps someone with Visual Studio 2019. I was missing a simple /
Steps: Right Click Project -- Add > Existing Item -- Select Picture to add -- Click on picture in visual Studio -- go to properties -- change Build Action to > Recources
no we go into Xaml and add your resource
<UserControl.Resources>
<Image x:Key="ButtonImage" Source="/image.jpg"/>
</UserControl.Resources>
the / before the image name is a must. Without the / it will show up as working in xaml but once you start the program it wont show.
<Button Content="{StaticResource ButtonImage}"></Button>
I hope that fixes it if you read this
The following worked for me:
• Build Action = Resource
• Copy to Output Directory = Do not copy
xaml:
<Image Source=“Rsources/myPic.png”/>
Where “myPic.png” is the image inside “Resources” folder
Well, I waisted more than 3 hours of my time on this problem. Your answers helped me to partially solve the problem and that's what urged me to add to this useful discussion.
I got my problem solved as:
After all of that I found my self when I use the image multiple times or try to change to another image on the same image control to change the path for the image either on XAML or in the image control properties to be:
source="pack:://siteoforigin:,,,/Resources/image.png"
Please check image is included in solution or not. If image is not included then click on Show All Files from solution and then right click on image and select Include In Project option. After that it will work with relative path as well.
Ex:
" Source="/Images/Logo/close.png" "
Maybe the Image does not have the Build Action set to Resource. If it's anything else, including Embedded Resource, then it will not display properly at runtime.
siteoforigin
is for files copied to the executable directory or subdirectories, for resources you should use application
as authority as far as i know.
SiteOfOrigin:
Path: The name of the site of origin file, including its path relative to the location from which the executable assembly was launched.