Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Excuse the novice question, I'm new to wpf.

I want to use an image as the "Icon" of a xaml window. I want this image to be embedded in the exe.

what's the best way?
Please include ALL required steps.


---------------
so far, I've tried this:
HTML
<Window ... 
   Icon="{StaticResource MyIco}">
...

<BitmapImage x:Key="MyIco" UriSource="TheIco" />


TheIco is a resource I've added and which I can see in the Resources.resx file
---------------
What am I doing wrong or what's the best way to do this?



Thanks,
Herb
Posted
Updated 10-Feb-14 2:29am
v4
Comments
Joezer BH 10-Feb-14 8:33am    
It's nice to see a novice question with the user bothering to write down what he tried, I've 5ed your question for that.

Cheers, C

1 solution

Add image to the project as a file, not to Resources.resx. And look at this article
 
Share this answer
 
Comments
Herbisaurus 10-Feb-14 10:51am    
Hmm,
Can you specify the steps in more details.

I have the file in my project of course already, using:
Icon="MyProject.MyIco" in the Window element does not work.
The MyProject.MyIco is not recognized.
Irina Pykhova 10-Feb-14 11:35am    
Add image file to application root, make sure that Buiild action for it is set to Resource. Then in xaml set Icon="myImage.ico". That's all. If you added image to some subfolder, you should write exact path to this image. But you don't need to write project name. Try to remove 'MyProject'
Herbisaurus 10-Feb-14 10:54am    
I am not sure your suggestion qualifies. In your approach, will the image be embedded in the assembly as I requested?
Irina Pykhova 10-Feb-14 11:36am    
yes, if Build Action is Resource
Herbisaurus 11-Feb-14 5:40am    
Thanks, What if I want to set that resource in code:I tried this:

img.Source = new BitmapImage(new Uri(@"pack://application:,,,/Images/MyPic.jpg"));

But I get IOException (cannot locate resource)is my code line good for that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900