图像源路径在 xaml 中是什么意思? [英] What do image source paths mean in xaml?

查看:27
本文介绍了图像源路径在 xaml 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看我在 Visual Studio 中处理的项目的源代码,路径在 WPF 窗口 XAML 中看起来很奇怪.例如,window 元素的图标成员如下所示:Icon="/ProjectName;component/icons/ProjectName.ico"

I'm looking at the source code for the project I'm working on in Visual Studio, and the paths look weird in the WPF window XAML. For example, the icon member of the window element looks like this: Icon="/ProjectName;component/icons/ProjectName.ico"

首先,分号是什么意思?这是否表示两条可能的路径?这没有意义.

First of all, what does the semicolon mean? Does that indicate two possible paths? That doesn't make sense.

我猜 ProjectName;component 代表一个路径,因为我的项目中没有 component 文件夹.在我的项目文件夹中,icons/ProjectName.ico 是图标所在的位置.

I'm guessing ProjectName;component represents a path, because there's no component folder in my project. In my project folder, icons/ProjectName.ico is where the icon is.

这一切意味着什么?

推荐答案

那是一个资源文件包 URI,不带前缀 pack://application:,,,,由 XAML 解析器自动添加.

That is a Resource File Pack URI, without the prefix pack://application:,,,, which is automatically added by the XAML Parser.

完整的 Pack URI 将是

The full Pack URI would be

pack://application:,,,/ProjectName;component/icons/ProjectName.ico

并且会在被引用程序集ProjectNameicons 子文件夹中引用名为ProjectName.ico 的资源文件.;component 部分将程序集名称与文件路径分开.

and would reference a resource file named ProjectName.ico in an icons subfolder in the referenced assembly ProjectName. The ;component part separates the assembly name from the file path.

如果资源文件在本地程序集中,可以省略引用的程序集部分,而写

If the resource file is in the local assembly, you could omit the referenced assembly part, and write

pack://application:,,,/icons/ProjectName.ico

或仅在 XAML 中

/icons/ProjectName.ico

这篇关于图像源路径在 xaml 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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