资源图像的绝对UriSource [英] Absolute UriSource of a Resource image

查看:93
本文介绍了资源图像的绝对UriSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF项目。如果我存储图像{ProjectRoot} \图片\ image.png,并将其编译为资源,那么我可以通过的BitmapImage UriSource =图片从一个XAML访问它(XAML是位于根)作为BitmapImage的/image.png。但是,如果我将XAML到另一个文件夹,说{ProjectRoot} \ Xamls,现在我必须使用的BitmapImage UriSource =../图像/ image.png。有没有一种方法来指定一个绝对项目路径,这样我可以参考的XAML的位置,他们具有相同的路径不管?

I have a WPF project. If I store image in {ProjectRoot}\Images\image.png, and compile it as Resource then I can access it from a xaml (this xaml is located at Root) as BitmapImage by BitmapImage UriSource="Images/image.png". But if I move the xaml to another folder, say {ProjectRoot}\Xamls, now I have to use BitmapImage UriSource="../Images/image.png". Is there a way to specify an absolute project path, so that I can refer to them with the same path regardless of the location of the xaml?

推荐答案

您可以通过绝对路径使用此语法既要参考同一个项目中,或在其他项目的参考文件:

You can use this syntax both to reference by an absolute path inside the same project, or reference files in other projects:

UriSource="/MyAssemblyName;component/Images/image.png"

下面MyAssemblyName的项目/ DLL / EXE的名称和组件表示项目的根。

Here "MyAssemblyName" is the project/dll/exe name and "component" indicates the project root.

这篇关于资源图像的绝对UriSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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