134

Before going much further i'll mention I have tried solutions in following:

How do I set the icon for my application in visual studio 2008?

Set application icon from resources in VS 05

I am trying to set an icon for my application.

AFAIK, I need potentially 3 images?

  • 1 image is the actual image in explorer when clicking on the .exe (thumbnail for the exe)
  • 1 image (tiny) in the top left corner (16 x 16? Not entirely sure)
  • 1 image in the start menu dock, to the left of the app (maybe 32x32? again not sure)

So thats fine.

Now I have selected an Icon. How do I use it in one of above situations?

I have tried adding it in resources, nothing seems to happen. Following that first SO solution,

"First go to Resource View (from menu: View --> Other Window --> Resource View). Then in Resource View navigate through resources, if any. If there is already a resource of Icon type, added by Visual Studio, then open and edit it. Otherwise right-click and select Add Resource, and then add a new icon."

The resource view is empty, and I cannot right click in this view.

If I right click on the solution > properties > resources > I can add the icon image, but it doesn't show in either of the locations listed above. (or anywhere that I can see)

1) How do I set the application icon for a WPF Application?

Community
  • 1
  • 1
baron
  • 11,011
  • 20
  • 54
  • 88
  • Actually that is Win 7 Talk; XP we only have two I think? the 16 x 16 and the big thumbnail for the exe (not sure size) – baron Apr 20 '10 at 05:16
  • For anyone interested, I set one Icon, the image was 64 x 64 and everything else (the smaller sizes) were made automatically from scaling the original image I provided. – baron May 03 '10 at 06:05
  • Check out this question on SuperUser http://superuser.com/questions/142731/which-dlls-included-in-windows-contain-icons for getting built in windows icons into your app easily. – Chris Marisic Nov 06 '14 at 18:08
  • This was helpful: http://www.rw-designer.com/image-to-icon – Andrew Jul 20 '18 at 21:23

5 Answers5

172

Assuming you use VS Express and C#. The icon is set in the project properties page. To open it right click on the project name in the solution explorer. in the page that opens, there is an Application tab, in this tab you can set the icon.

742
  • 3,009
  • 3
  • 23
  • 18
  • 2
    Thank you for your answer... everything else I have found explains messing around in the resources, but following your solution resources was left completely alone and just set it in the Application tab. Cheers – baron May 03 '10 at 06:06
  • 61
    Yes. This worked for me. However, it appears that when running the application from the VS debugger (ie pressing F5), the 'generic' icon is still shown. However, running without the debugger (ie ctrl + f5, or from desktop etc) shows the custom icon, as expected. – Tom Dec 13 '11 at 02:33
  • 7
    That is because, when the debugger runs your code it uses the vshost.exe version of your build (to aid debugging) which uses the default application icon and NOT the icon set in the applications tab, as this is set for yourapplication.exe – VisualBean Mar 06 '15 at 11:04
  • This worked for me. Even in debug mode. Cause I don't have any default icon set. – Moses Dec 13 '21 at 05:30
96

@742's answer works pretty well, but as outlined in the comments when running from the VS debugger the generic icon is still shown.

If you want to have your icon even when you're pressing F5, you can add in the Main Window:

<Window x:Class="myClass"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Icon="./Resources/Icon/myIcon.png">

where you indicate the path to your icon (the icon can be *.png, *.ico.)

(Note you will still need to set the Application Icon or it'll still be the default in Explorer).

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
astreal
  • 3,383
  • 21
  • 34
  • 8
    Setting both is good because it seems to be required for the icon to appear on both the window and the EXE file. – Vimes Apr 18 '13 at 23:22
  • 4
    Just make sure to set the icon to a build action of "Resource" as @AdamDylla said: stackoverflow.com/a/39897641/1703887 – csrowell Aug 25 '17 at 15:00
9

Note: (replace file.ico with your actual icon filename)

  1. Add the icon to the project with build action of "Resource".
  2. In the Project Properties, set the Application Icon to file.ico
  3. In the main Window XAML set: Icon=".\file.ico" on the Window
Adam Dylla
  • 91
  • 1
  • 4
3

After getting a XamlParseException with message: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' with the given solutions, setting the icon programmatically worked for me. This is how I did it:

  1. Put the icon in a folder <icon_path> in the project directory
  2. Mimic the folder path <icon_path> in the solution
  3. Add a new item (your icon) in the solution folder you created
  4. Add the following code in the WPF window's code behind:

Icon = new BitmapImage(new Uri("<icon_path>", UriKind.Relative));

Please inform me if you have any difficulties implementing this solution so I can help.

Marvin Thobejane
  • 2,010
  • 1
  • 19
  • 13
  • 1
    The easy fix for this error message is to set the icon to a build action of "Resource" as @AdamDylla said: https://stackoverflow.com/a/39897641/1703887 – csrowell Aug 25 '17 at 15:00
2

You can try this also:

private void Page_Loaded_1(object sender, RoutedEventArgs e)
    {
        Uri iconUri = new Uri(@"C:\Apps\R&D\WPFNavigation\WPFNavigation\Images\airport.ico", UriKind.RelativeOrAbsolute);
        (this.Parent as Window).Icon = BitmapFrame.Create(iconUri);
    }
Nadeem Shaikh
  • 117
  • 14