WPF Icon for all app windows

WpfIconsWindow

Wpf Problem Overview


It is possible to set one Icon so, that it would be used on every window in current app. So that i set it once (not on every window by hand)..?

Wpf Solutions


Solution 1 - Wpf

A good reference on the subject is here MSDN. States that you have an Icon for the Application (Desktop Icon), and one for each Window.

A WPF window always displays an icon. When one is not provided by setting Icon, WPF chooses an icon to display based on the following rules:

  1. Use the assembly icon, if specified.

  2. If the assembly icon is not specified, use the default Microsoft Windows icon.

Community Content Reference:

"A liitle tip : if you set the application icon and expect to see it on the window - it wont show up if running in debug from VS. Running externally or without attaching (ctrl + f5) the icon displays as expected."

Solution 2 - Wpf

Set the icon in the project properties on the "Application" tab in the "Resources" section. This icon will be the default icon for all windows in the application.

Solution 3 - Wpf

Under VS2010 open the Properties for the main application executable and open the Application tab. Set the icon under 'Icon and Manifest' in the Resources section.

To see the icon while debugging under VS2010 you need to open the Debug tab and uncheck the option for 'Enable the Visual Studio hosting process', otherwise you will only see the default icon on most windows.

I assume that the icon loading code is getting confused by the hosting process and is looking in "someapplication.vshost.exe" instead of "someapplication.exe" for the icons.

This looks like it's fixed in VS2013.

Solution 4 - Wpf

The reason that "Enable the Visual Studio hosting process" makes the icon not work is that it is started using the vshost.exe, and thereby the manifest is not read properly. The same goes if you have other stuff in the manifest, like regfree ocx controls etc that requires the manifest to load.

Solution 5 - Wpf

You can also try this to set your own icon:

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);
        }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionvts123View Question on Stackoverflow
Solution 1 - WpfjsmithView Answer on Stackoverflow
Solution 2 - WpfJohn MyczekView Answer on Stackoverflow
Solution 3 - WpfDaveClelandView Answer on Stackoverflow
Solution 4 - WpfFrostyView Answer on Stackoverflow
Solution 5 - WpfNadeem ShaikhView Answer on Stackoverflow