Answered by:
Adding an Icon to the main window

Question
-
I have an Icon in .ico format. It's loaded into the "My Project" Resouces tab (of VS 2008) as an Icon and can be seen in the "Resources" folder within both VS 2008 and Expression Blend (1 and 2beta). When I click on the Icon dropdown within Blend, I can see the Icon listed. If I select the .ico file, Icon="Resources\Icon1.ico" gets added to the XAML in the appropriate place.
However, when I try to run it from Blend I get a run time error. If I open it in VS 2008, I can see an error:
The file Resources\Icon1.ico is not part of the project or its 'Build Action' property is not set to 'Resource'.
So, I went back and selected the Icon from the Resources folder and made sure the "Build Action" property was set to "Resource" and the "Copy to Output Directory" property was set to "Copy if newer". Still, I get the same design time error. Needless to say, I get a run time error as well.
If, instead of the above XAML, I assigned the Icon property by using the VS2008's Properties box's dropdown. It suggested the following:Icon="/MyAssemblyName;component/Resources/Icon1.ico"
If I update the XAML manually, the code now is error free in both VS 2008 and Blend.
So, this syntax is URI stuff, but doesn't seem to be available from Blend. How should one assign an icon to a window from the Blend designer?Wednesday, May 7, 2008 7:37 PM
Answers
-
Here is what worked for me
I have Icon inside of a folder called Images. In XAML the Icon is assigned as Icon="Images\myicon.ico"
In Blend, I can see the Icon on the Windows title bar. In VS 2008, I don't see this in design view, but see it at run time.
The settings on the icon file are - "Resource" and "Do not copy". If the file is marked as Resource, then it will get embedded inside of the assembly and hence copying to output folder isn't required.
Do note that I am working with Expression Blend 2.5 and VS 2008 RTM
MVP Client App- Marked as answer by Lori DirksModerator Sunday, November 23, 2008 3:51 AM
Thursday, May 8, 2008 2:19 AM
All replies
-
Here is what worked for me
I have Icon inside of a folder called Images. In XAML the Icon is assigned as Icon="Images\myicon.ico"
In Blend, I can see the Icon on the Windows title bar. In VS 2008, I don't see this in design view, but see it at run time.
The settings on the icon file are - "Resource" and "Do not copy". If the file is marked as Resource, then it will get embedded inside of the assembly and hence copying to output folder isn't required.
Do note that I am working with Expression Blend 2.5 and VS 2008 RTM
MVP Client App- Marked as answer by Lori DirksModerator Sunday, November 23, 2008 3:51 AM
Thursday, May 8, 2008 2:19 AM -
Thanks!
I have used your suggestion successfully. However, regardless of the technique I use, I never seem to be able to see the Icon in the designer of VS2008.
I have set the properties to Resource and Do Not Copy. I seem to recall that when I tried this the last time the icon was absent in the the app when I deployed by Click Once but returned when I copied the icon to the output. I will retest this.
MFriday, May 9, 2008 2:06 PM -
As I mentioned earlier, VS doesn't shows this icon in title bar in design view. It is only visible on runtime. However Expression does shows this in design view as well, so if you have Expression, you can view the icon in design mode as well.
MVP Client AppSunday, May 11, 2008 5:13 AM