question

TomHintz-3948 avatar image
0 Votes"
TomHintz-3948 asked 47418195 commented

WPF: Cannot locate resource 'resource/favicon.ico' on main Window Icon (simple question)

I created my fist WPF app under .Net Core 3.1 in the latest VS 2019. Its just the stock Window when the project is first created and I want to set the Windows icon so I visited the project properties and clicked the link to add Resources. This creates Resources.resx under a Properties folder. I imported an existing favicon.ico into the resources and then tried setting the main Window's Icon="Resources/favicon.ico" resulting in an error for that property.

I've read that a "build action" is needed but I see no button or property for that.

How is the problem resolved? Thanks,

windows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ZhanglongWu-MSFT avatar image
2 Votes"
ZhanglongWu-MSFT answered 47418195 commented

Hi TomHintz,

In Solution Explorer set the image file's Build Action property to Resource. Then clean the solution and rebuild it.

29189-2020093001.png




Best regards,
Zhanglong


2020093001.png (23.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Niubility,bro.Worked like a charm.
Best to set the "Copy to Output Directory" to "Copy always" or "Copy if newer", too.

0 Votes 0 ·
TomHintz-3948 avatar image
0 Votes"
TomHintz-3948 answered

Thank you for the answer. Actually, I had imported an existing item into the resource, but that does not copy the resource into the resource folder. I manually copied the resource and then your solution works.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.