资源图片的绝对UriSource

发布于 2024-10-09 12:01:30 字数 338 浏览 0 评论 0原文

我有一个 WPF 项目。如果我将图像存储在 {ProjectRoot}\Images\image.png 中,并将其编译为资源,那么我可以通过 BitmapImage UriSource="Images/image.png" 作为 BitmapImage 从 xaml(此 xaml 位于根目录)访问它。 png”。但是,如果我将 xaml 移动到另一个文件夹(例如 {ProjectRoot}\Xamls),现在我必须使用 BitmapImage UriSource=".​​./Images/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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§普罗旺斯的薰衣草 2024-10-16 12:01:30

您可以使用此语法来通过同一项目内的绝对路径进行引用,也可以引用其他项目中的文件:

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

此处“MyAssemblyName”是项目/dll/exe 名称,“component”表示项目根目录。

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"

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文