Taskbar ugly icon in WPF application

a 夏天 提交于 2020-01-01 04:33:08

问题


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!


回答1:


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.




回答2:


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/




回答3:


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.



来源:https://stackoverflow.com/questions/12901212/taskbar-ugly-icon-in-wpf-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!