【发布时间】:2012-03-14 05:53:44
【问题描述】:
我有几张图片想要嵌入到 exe 中。
当我将 Build Action 设置为 Embedded Resource 我通过代码找到资源不可用的错误,并要求我将构建操作设置为 Resource
我尝试了几种不同的方法:
<ImageSource x:Key="Image_Background">YearBook;component/Resources/Images/darkaurora.png</ImageSource>
<ImageSource x:Key="Image_Background">Images/darkaurora.png</ImageSource>
<ImageSource x:Key="Image_Background">pack://application:,,,/Resources/Images/darkaurora.png</ImageSource>
此代码位于资源文件中。 但是没有一个起作用,他们都抛出了这个错误:
Cannot convert the string 'pack://application:,,,/Resources/Images/darkaurora.png' into a 'System.Windows.Media.ImageSource' object. Cannot locate resource 'resources/images/darkaurora.png'. Error at object 'Image_Background' in markup file 'YearBook;component/Resources/ImageResources.xaml' Line 4 Position 6.
我在代码中的不同位置得到:
the file 'YearBook;component/Resources/Images/shadowdrop.png' is not a part of the project or its 'Build Action' property is not set to 'Resource'
那么,我做错了什么?
【问题讨论】:
标签: c# .net wpf xaml embedded-resource