Specifying Window icon via string isn't working

Using Feb. CTP:

I have a WinFX control library which contains various Window objects. The project layout looks like this:

- DefaultUI.csproj
- LoginScreen
- LoginScreen.xaml (Window)
- Images
- icon.ico (Resource)

Unfortunatly, I can't figure out how to specify the Window's Icon property in XAML. In other control libraries I was able to use Icon="/Images/icon.ico" and it would work; however, in this particular project that fails with a BamlParseException in InitializeComponent:

"Error at element 'LoginScreen' in markup file 'DefaultUI;component/loginscreen/loginscreen.xaml' : '/Images/icon.ico' string is not a valid value for 'Icon' property of type 'ImageSource'."

I have tried /Images/icon.ico, Images/icon.ico, pack://application:,,,/Images/icon.ico, and pack://siteoforigin:,,,/Images/icon.ico - all fail in the same way. I've also tried including the icon as Content instead of Resource, no luck.

It's not just the icon behaving this way, there is another image included in that project and trying to reference it fails as well.


Answer this question

Specifying Window icon via string isn't working

  • Ian Waters

    Bump for the weekday crew...

  • Elijah

    Theres another thread with the same issue which might be of help

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=524852&SiteID=1


  • DarkOasis

    I have the same problem, but your solution didn't work for me.
    I code a game named zyDefender (I think I'll change the name, "Windows Defender" didn't exist when I had the idea, or I didn't know it). The funny thing is that I compiled and used the code successfully 2 das ago. Yesterday I tried to run my game again after making a few changes of the game logic (not the UI). Now I allways get an exception telling that my string is not a valid value for the Icon property of type ImageSource.
    The Icon is an ico-File Defender.ico added to the Solution in a new folder called Images.
    I tried the following strings in the Icon property of the Window:
    Defender.ico
    Images/Defender.ico
    /Images/Defender.ico
    /zyDefender;component/Images/Defender.ico
    /zyDefender;Images/Defender.ico
    zyDefender;component/Images/Defender.ico
    zyDefender;Images/Defender.ico
    zyDefender/Images/Defender.ico
    allways the same exception :(

  • trulyviral

  • Ashwin Panse - MSFT

    thx, I installed WIC a few days ago hoping being able to install the new Interactive Designer, which still says it needs Beta 2. I don't really need WIC or the designer.
    So I removed it and I can run my game successfully.

  • Amorano

    When you add a leading slash to a relative Uri, you're effectively saying "look for this file relative to the application".

    I'm assuming the icon is embedded into the library (i.e. declared as Resource in the library's project file). In that case, the sure fire way of referencing it is using a relative Uri like "/DefaultUI;component/Images/icon.ico". Here you're saying "look for a reference library DefaultUI.dll relative to the application and then look for icon.ico in the Images folder inside it". Such a reference will work when made from a XAML inside the library or inside the application which has the aforementioned library as reference assembly. Hope that helps.



  • ramkanna

    That did the trick, thanks!

  • Specifying Window icon via string isn't working