我有几个图像想要嵌入到 exe 中。
当我设置构建行动 to 嵌入式资源我在代码中发现了资源不可用的错误,并要求我将构建操作设置为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'
那么,我做错了什么?
当您设置构建动作 to Resource它作为程序集中的嵌入资源。
或者你可以设置构建动作 to Content然后它将捆绑到生成的 .xap 文件中。
您可以使用这些 BuildAction 中的任何一种。通过设置构建动作 to Content您可以像这样访问图像:"/Resources/Images/darkaurora.png"
(必须以斜线开头)。当你使用构建行动资源然后你可以访问图像"/YearBook;component/Resources/Images/darkaurora.png"
(程序集名称;组件/相对路径)。希望这会有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)