WPF throws “Cannot locate resource” exception when loading the image

白昼怎懂夜的黑 提交于 2019-12-17 16:30:31

问题


I am having a WPF window, with a background image of one file in my local system. So the XAML file looks like this:

 <Window.Background>
    <ImageBrush ImageSource="/MYASSEMBLY;component/Resources/MyPic.png"/>
 </Window.Background>

In the XAML designer it actually shows this background image, so the image does exist in MYASSEMBLY\Resources folder. However, in the InitializeComponent() function call when I launch the application, it throws the exception

Cannot locate resource 'resources/mypic.png'.

So I am totally lost now. Are the directories different between the design and runtime so doesn't exist in the runtime?


回答1:


In the solution explore, set the image "Build Action" property to "Resource" ,then clean the solution and rebuild it.



来源:https://stackoverflow.com/questions/11948829/wpf-throws-cannot-locate-resource-exception-when-loading-the-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!