How to display a .ico image file in a XAML app?
Asked Answered
D

1

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?

Diplomat answered 10/8, 2016 at 18:28 Comment(8)
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.Guendolen
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.Diplomat
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: image.online-convert.com/convert-to-jpgGuendolen
Right. But I find it hard to believe that a .ico file can't be displayed in a simple Image control somehow.Diplomat
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.Cheapskate
When adding the .ico to your project did, did you set the properties of the .ico to Copy Always and Content?Derivation
@Derivation I tried setting the properties to Content and Copy Always without success.Diplomat
@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.Diplomat
D
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

Diplomat answered 11/8, 2016 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.