如何从XAML请参阅嵌入式资源? [英] How to refer to Embedded Resources from XAML?

查看:209
本文介绍了如何从XAML请参阅嵌入式资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要被嵌入到exe多张图像。

I have several images that i want to be Embedded into the exe.

当我将生成操作嵌入的资源 我打通了C时错误的资源不可用$ C $和要求我设置生成操作为资源

When i set the Build Action to Embedded Resource I get through out the code an error that the Resource isn't available and asking me to set the Build Action to Resource

我试了几种不同的方法:

I Tried several different methods :

 <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>

这code坐落在一个资源文件。 但没有工作,他们都抛出此错误:

This code sits in a Resource file. But none worked, they all throw this error :

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.

和在code不同的地方,我得到:

And in different places in code i get :

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'

那么,什么是我做错了吗?

So, What am i doing wrong?

推荐答案

在您设置的的BuildAction 资源它会在程序集嵌入的资源。 或者你也可以将的BuildAction 内容,然后它会捆绑到生成的.xap文件。 可以使用这些BuildActions中的任何一个。通过设置的BuildAction 内容您可以访问图片,如: /资源/图像/ darkaurora.png(必须以斜杠)。而当你使用 BuildAction的资源,然后你可以访问图像作为年鉴;组件/资源/图像/ darkaurora.png(的AssemblyName;组件/ relativepath)。希望这会有所帮助。

When you set the BuildAction to Resource it goes as embedded resource in an assembly. Or you can set BuildAction to Content then it will bundled into the resulting .xap file. You can use any one of these BuildActions. By setting BuildAction to Content you can access Image like: "/Resources/Images/darkaurora.png" (must begin with slash). And when you use the BuildAction Resource then you can access image as "YearBook;component/Resources/Images/darkaurora.png" (assemblyname;component/relativepath). Hope this will help.

这篇关于如何从XAML请参阅嵌入式资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆