Friday, April 20, 2012

How to refer to Embedded Resources from XAML?

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?





No comments:

Post a Comment