Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taskbar ugly icon in WPF application

Tags:

icons

wpf

The icon in the taskbar is looking very ugly in my WPF application.

The designer sent me some PNGs like:

32x32, 64x64, 96x96, 128x128, 192x192, 256x256, 512x512.

What do I have to do to get the goodloking taskbar icon?

Thank you!

like image 334
Friend Avatar asked Oct 15 '12 17:10

Friend


3 Answers

Make an .ico file containing multiple sizes. At a minimum, you should have the following sizes: 16x16, 32x32, 48x48, and 256x256 according to the Windows icon visual guidelines. Having a single .ico file will help Windows pick the best size and scale it appropriately depending on the situation (application icon, large taskbar, small taskbar, etc.)

If you aren't a designer, then it's also better to let your designer make the 16x16 image, since it's possible the larger images you have have too much detail and do not scale down very well. If the larger images are very detailed, then the designer could make the smaller images simpler so that the icon shows better. The visual guidelines linked above have more tips about this.

like image 174
Stephen Booher Avatar answered Nov 16 '22 19:11

Stephen Booher


Taskbar icons seem to get blurry as soon as a 48x48 pixels version is included in the .ico file. Instead of picking the correctly sized 32x32 pixels version, for some reason Windows apparently picks the 48x48 one and scales it down.

The solution for me is to use two separate icon files:

  • One .ico containing 24x24 and 32x32 versions of the icon, which will, when set as a Window's icon using the Icon property in XAML or Hannish's approach, be used for the titlebar and taskbar respectively - without unwanted scaling.
  • A second icon file containing - depending on which sources are right - a range of sizes between 16x16 and 256x256 pixels. Setting this one as the application icon in the project properties will make the icon look good in all the other places like the desktop and the file explorer on different view settings.

Testing on Windows 10, this seems to cover the following display cases: taskbar, window titlebar, Alt-TAB menu, Desktop and file explorer.

like image 8
Joe Bloe Avatar answered Nov 16 '22 17:11

Joe Bloe


I had the same problem, it was not working even with a multi-sized .ico file. Setting the icon directly in the Window resulted in a pixelated icon.

I managed to fix it with this code-behind for the application window:

private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        Uri iconUri = new Uri("pack://application:,,,/Images/myicon.ico", UriKind.RelativeOrAbsolute); //make sure your path is correct, and the icon set as Resource
        this.Icon = BitmapFrame.Create(iconUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

        //etc.
    }

Icon file is multi-sized, this worked for me in WPF - Windows 10.

You can convert your .png icon into a multi-sized .ico file here http://icoconvert.com/

like image 6
Hannish Avatar answered Nov 16 '22 17:11

Hannish