Taskbar ugly icon in WPF application

前端 未结 3 692
醉梦人生
醉梦人生 2021-02-14 15:41

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

相关标签:
3条回答
  • 2021-02-14 15:56

    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.

    0 讨论(0)
  • 2021-02-14 15:58

    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.

    0 讨论(0)
  • 2021-02-14 16:08

    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/

    0 讨论(0)
提交回复
热议问题