Displaying icons in Image control - inconsistent behavior<p>I have some xaml:</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left> </p> <p align=left><font face=Courier>&lt;Window<br> x:Class=&quot;Windowing.MyWindow&quot;</font></p> <p align=left><font face=Courier> &gt;<br>  &lt;StackPanel&gt;<br>   &lt;TextBlock Text=&quot;This is a window!&quot;/&gt;<br>   &lt;Image Source=&quot;image.ico&quot;/&gt;<br>  &lt;/StackPanel&gt;<br>&lt;/Window&gt;</font></p></blockquote> <p> </p> <p align=left>(I also have a trivial code-behind that calls InitializeComponent in the constructor.)</p> <p align=left> </p> <p align=left>I open instances of this Window like this:</p> <p align=left> </p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>  <font face=Courier> MyWindow win = <br>    new MyWindow();<br>   win.Show();  <br></font>  </p></blockquote> <p>When I open a single instance of this Window, this works fine. But as soon as I open a second instance, the image stops appearing. This issue does not occur with a PNG. Both are declared as resources in the project file like this:</p> <p align=left> </p> <blockquote dir=ltr style="margin-right:0px"> <p align=left><font face=Courier> &lt;Resource Include=&quot;image.ico&quot;/&gt;</font></p></blockquote> <p align=left> </p> <p align=left>I am seeing hints that the Image control won't take an icon as a Source without some preprocessing, yet it seems to work for a single Window. I can create as many instances of the icon as I want in dfferent Image controls within a single Window.</p> <p align=left> </p> <p>Are resource files in an assembly handled differently when they are icons, or is the difference based on the behavior of the Image control? What causes this behavior?</p> <p align=left> </p> <p align=left>Thanks,</p> <p align=left>Steph</p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Zbebf27e5-393b-4a8b-bd79-252215ebe095http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#bebf27e5-393b-4a8b-bd79-252215ebe095http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#bebf27e5-393b-4a8b-bd79-252215ebe095Steph Grushhttp://social.msdn.microsoft.com/Profile/en-US/?user=Steph%20GrushDisplaying icons in Image control - inconsistent behavior<p>I have some xaml:</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left> </p> <p align=left><font face=Courier>&lt;Window<br> x:Class=&quot;Windowing.MyWindow&quot;</font></p> <p align=left><font face=Courier> &gt;<br>  &lt;StackPanel&gt;<br>   &lt;TextBlock Text=&quot;This is a window!&quot;/&gt;<br>   &lt;Image Source=&quot;image.ico&quot;/&gt;<br>  &lt;/StackPanel&gt;<br>&lt;/Window&gt;</font></p></blockquote> <p> </p> <p align=left>(I also have a trivial code-behind that calls InitializeComponent in the constructor.)</p> <p align=left> </p> <p align=left>I open instances of this Window like this:</p> <p align=left> </p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>  <font face=Courier> MyWindow win = <br>    new MyWindow();<br>   win.Show();  <br></font>  </p></blockquote> <p>When I open a single instance of this Window, this works fine. But as soon as I open a second instance, the image stops appearing. This issue does not occur with a PNG. Both are declared as resources in the project file like this:</p> <p align=left> </p> <blockquote dir=ltr style="margin-right:0px"> <p align=left><font face=Courier> &lt;Resource Include=&quot;image.ico&quot;/&gt;</font></p></blockquote> <p align=left> </p> <p align=left>I am seeing hints that the Image control won't take an icon as a Source without some preprocessing, yet it seems to work for a single Window. I can create as many instances of the icon as I want in dfferent Image controls within a single Window.</p> <p align=left> </p> <p>Are resource files in an assembly handled differently when they are icons, or is the difference based on the behavior of the Image control? What causes this behavior?</p> <p align=left> </p> <p align=left>Thanks,</p> <p align=left>Steph</p>Thu, 04 Oct 2007 22:57:55 Z2007-10-09T22:47:17Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#cb276c2c-619c-46d2-9079-d157a3765306http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#cb276c2c-619c-46d2-9079-d157a3765306Dr. WPFhttp://social.msdn.microsoft.com/Profile/en-US/?user=Dr.%20WPFDisplaying icons in Image control - inconsistent behavior<p align=left><font face=Arial size=2>I can't repro this.  I can open as many instances of the window as I want and they all contain the ico Image.  Do you have a small repro that you can post somewhere?</font></p>Fri, 05 Oct 2007 05:00:14 Z2007-10-05T05:00:14Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#185cbb16-a6d1-46da-a2c2-7ff5ea49cc4ahttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#185cbb16-a6d1-46da-a2c2-7ff5ea49cc4aSteph Grushhttp://social.msdn.microsoft.com/Profile/en-US/?user=Steph%20GrushDisplaying icons in Image control - inconsistent behavior<p align=left><font face=Arial size=2>I have uploaded my test project here:</font></p> <p align=left> </p> <p align=left><a title="http://steph.grush.googlepages.com/icondisplayersample" href="http://steph.grush.googlepages.com/icondisplayersample">http://steph.grush.googlepages.com/icondisplayersample</a></p> <p align=left> </p> <p align=left>Interesting that it seems to work for you. I wonder if I have done something wrong. Please let me know if the sample reproduces the issue for you, and if not, what version of the framework you have - I have not installed the 3.5 beta yet.</p> <p align=left> </p> <p align=left>The error occurring in the sample code appears to be an ImageFailed event. The MSDN library says that </p> <blockquote> <p><em>Conditions in which this event can occur include: </em></p> <ul> <li><em>File not found. </em> <li><em>Invalid file format - unrecognized or unsupported format. </em> <li><em>Unknown file format decoding error after upload.</em> </li></ul></blockquote> <p align=left>It doesn't seem like any of these things could be happening, however, since the image is displayed the first time.</p> <p align=left> </p> <p align=left>Thanks,</p> <p align=left>Steph</p>Mon, 08 Oct 2007 19:32:05 Z2007-10-08T19:32:05Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#15ba4dcf-b229-447c-bbee-43f5a2f0b4e5http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#15ba4dcf-b229-447c-bbee-43f5a2f0b4e5Dr. WPFhttp://social.msdn.microsoft.com/Profile/en-US/?user=Dr.%20WPFDisplaying icons in Image control - inconsistent behavior<p>Weird!</p> <p align=left> </p> <p align=left>It's not anything you're doing wrong.  It's something about that particular icon.</p> <p align=left> </p> <p align=left>I dropped in about a dozen other icons from my system and *most* of them worked fine.  I found one other icon that failed in the same manner as your &quot;unknown.ico&quot;.  I opened all the icon files in Photoshop Elements to look for commonalities.  The ones that worked always had a number of icons in the common formats and sizes.  However, the 2 that failed (mine and yours) both contained a number of normal formats plus one weird format:</p> <p align=left> </p> <p align=left>e.g., 169478669 x 109051904 @ 21060 bits/pixel</p> <p align=left> </p> <p align=left>Clearly, this is Elements not understanding the format.  I'm guessing the real format is one of the new 256x256 PNG compressed formats.</p> <p align=left><font face=Arial size=2></font> </p> <p>I'd say this represents a bug in WPF's icon bitmap decoder.  Very weird that it succeeds the first time and fails thereafter.  You should definitely submit your sample and this report to the <a title="https://connect.microsoft.com/feedback/default.aspx?SiteID=212" href="https://connect.microsoft.com/feedback/default.aspx?SiteID=212">WPF Connect</a> site.</p> <p align=left> </p> <p align=left>This bug repros on 3.5.</p>Mon, 08 Oct 2007 20:54:45 Z2007-10-08T20:54:45Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#d491971f-71c4-4ed0-ad2f-39939d3a89fbhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#d491971f-71c4-4ed0-ad2f-39939d3a89fbJordan Parker - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Jordan%20Parker%20-%20MSFTDisplaying icons in Image control - inconsistent behavior<p align=left><font face=Arial>Dr. WPF is correct -- that's a new Vista icon because it contains a PNG:</font></p> <p align=left> </p> <p align=left>&gt;findstr /sni PNG unknown.ico<br>unknown.ico:1:  ☺ ♣     ☺   ↕♫  V   @@  ☺   (B  h♫  00  ☺   ¿%  ÉP      ☺   ¿►  8v  ►►  ☺   h♦  αå  ëPNG</p> <p align=left> </p> <p align=left>Vista's PNG icons are not supported in WPF. Either remove the PNG candidate from the icon or re-save the icon as a bitmap. I did the latter and it worked fine.</p>Tue, 09 Oct 2007 20:18:56 Z2007-10-09T22:47:17Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#d6ab3341-12fc-499a-afab-f7de4e7526d8http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bebf27e5-393b-4a8b-bd79-252215ebe095#d6ab3341-12fc-499a-afab-f7de4e7526d8Steph Grushhttp://social.msdn.microsoft.com/Profile/en-US/?user=Steph%20GrushDisplaying icons in Image control - inconsistent behavior<p align=left><font face=Arial size=2></font> </p> <p>Good heavens! Somehow, it didn't even occur to me that WPF might not support vista icons, even though I knew Windows Forms didn't support them. You're absolutely right - that's the problem.</p> <p align=left> </p> <p align=left>Thanks for shedding light on a really mysterious issue.</p> <p align=left> </p> <p align=left>Steph</p>Tue, 09 Oct 2007 22:45:57 Z2007-10-09T22:45:57Z