6

Is it possible to display a .ico file in a XAML C# app? It's for a WinRT Windows Phone 8.1 app using Visual Studio 2015.

<Image Source="http://www.stackoverflow.com/favicon.ico"/> shows the icon fine in the designer, but not when run in the emulator.

I've tried using a downloaded icon, downloading an icon programmatically, saving as a .png file, loading from the LocalFolder, using the Assets folder, etc...but the image is still not shown. Seems like there should be an easy solution for this, or that it's just not possible.

Can it be done?

theMaxx
  • 3,756
  • 2
  • 27
  • 33
  • 1
    In a WPF app, you set the `Icon="myIcon.ico"` attribute on the Window's xaml. Not sure about WinRT. If you want to show it within the app itself, maybe try converting it to PNG or JPG and use an `Image` control. – Alex Aug 10 '16 at 18:36
  • I tried to programmatically save the ICO file using the PNG file extension and then set the Image control's Source to that, but it also did not display. It seems more that the image was not converted but just saved as the different file type. – theMaxx Aug 10 '16 at 18:45
  • Yeah, you're not changing the image type by just renaming it with a different extension. This free online tool will convert from ICO to JPG: http://image.online-convert.com/convert-to-jpg – Alex Aug 10 '16 at 18:46
  • Right. But I find it hard to believe that a .ico file can't be displayed in a simple Image control somehow. – theMaxx Aug 10 '16 at 18:51
  • The issue probably has something to do with the fact that you are using a remote image source. Is your windows phone device connected to the internet? Try attaching a listener to the ImageFailed event of the image and see events it emits. – 0xcaff Aug 11 '16 at 02:40
  • When adding the .ico to your project did, did you set the properties of the .ico to `Copy Always` and `Content`? – Barnstokkr Aug 11 '16 at 09:03
  • @Barnstokkr I tried setting the properties to Content and Copy Always without success. – theMaxx Aug 11 '16 at 17:21
  • @caffinatedmonkey I added a listener to the ImageFailed event of the image, and indeed it did fail, resulting in ErrorMessage E_NETWORK_ERROR. Using a different .png image resulted in an ImageOpened event. – theMaxx Aug 11 '16 at 17:25

1 Answers1

7

Basically...no, it's not possible.

The following working code that works in the designer and shows the image is very misleading:

<Image Source="http://www.stackoverflow.com/favicon.ico"/>

See this page for clear evidence: Windows class - Windows app development

Note Icon files supported on Windows only. Not supported on Windows Phone 8.1

theMaxx
  • 3,756
  • 2
  • 27
  • 33