Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have several images that i want to be Embedded into the exe.

When i set the Build Action to Embedded Resource I get through out the code an error that the Resource isn't available and asking me to set the Build Action to Resource

I Tried several different methods :

 <ImageSource x:Key="Image_Background">YearBook;component/Resources/Images/darkaurora.png</ImageSource>

 <ImageSource x:Key="Image_Background">Images/darkaurora.png</ImageSource>

 <ImageSource x:Key="Image_Background">pack://application:,,,/Resources/Images/darkaurora.png</ImageSource>

This code sits in a Resource file. But none worked, they all throw this error :

Cannot convert the string 'pack://application:,,,/Resources/Images/darkaurora.png' into a 'System.Windows.Media.ImageSource' object. Cannot locate resource 'resources/images/darkaurora.png'.  Error at object 'Image_Background' in markup file 'YearBook;component/Resources/ImageResources.xaml' Line 4 Position 6.

And in different places in code i get :

the file 'YearBook;component/Resources/Images/shadowdrop.png' is not a part of the project or its 'Build Action' property is not set to 'Resource'

So, What am i doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
296 views
Welcome To Ask or Share your Answers For Others

1 Answer

When you set the BuildAction to Resource it goes as embedded resource in an assembly. Or you can set BuildAction to Content then it will bundled into the resulting .xap file. You can use any one of these BuildActions. By setting BuildAction to Content you can access Image like: "/Resources/Images/darkaurora.png" (must begin with slash). And when you use the BuildAction Resource then you can access image as "/YearBook;component/Resources/Images/darkaurora.png" (assemblyname;component/relativepath). Hope this will help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...