什么是 Uri Pack,以及“:,,,”在位图图像中?

发布于 2024-10-24 19:06:12 字数 329 浏览 0 评论 0原文

我添加 Image.Source 的内容必须输入以下内容:

playIcon.Source = new BitmapImage(new Uri(@"pack://application:,,,/TempApplication2;component/Images/play.png"));

我正在从 Web 开发转向 WPF C#,我不明白为什么设置 Path 中有额外的内容,而在 CSS 中我只需添加一个 Path 字符串。

有人可以解释为什么有 Uri、pack 和“:,,,”Application2:组件吗?

我是 WPF C# 新手。

What I add a Image.Source I have to type the following:

playIcon.Source = new BitmapImage(new Uri(@"pack://application:,,,/TempApplication2;component/Images/play.png"));

I'm moving from web development to WPF C# and I don't get why setting a Path has extra stuff in it, where in CSS I simply add a Path string.

Can someone explain why there is Uri, pack, and the ":,,,", Application2:component?

I'm new to WPF C#.

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

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

发布评论

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

评论(2

写下不归期 2024-10-31 19:06:12

pack uri 用于识别&查找应用程序和远程中的资源、文件。
WPF 中的 pack uri 使用“pack://authority/path”格式。这是来自 MSDN 的一行,它解释了这种格式,“权限指定包含部件的包的类型,而路径指定包内部件的位置”

WPF 支持两种权限:application: ///siteoforigin:///application:/// 权限标识资源文件、内容文件。 siteoforigin:/// 权限标识源文件站点。

":///" 写作 ":,,," 因为 "/" 字符必须替换为 " ," 字符以及 "%""?" 等保留字符必须进行转义,并且指向包的 URI 必须符合 RFC 2396

有关详细信息,请阅读“Pack WPF 中的 URI

我也在学习 WPF。这就是我到目前为止对 WPF 中 Pack Uri 的理解。

The pack uri is used to identify & locate resources, files in application and remote.
The pack uri in WPF uses 'pack://authority/path' format. And this is the line from MSDN which explains this format, 'The authority specifies the type of package that a part is contained by, while the path specifies the location of a part within a package'

WPF supports two authorities: application:/// and siteoforigin:///. The application:/// authority identifies resource files, content files. The siteoforigin:/// authority identifies site of origin files.

":///" is written ":,,," because the "/" character must be replaced with the "," character, and reserved characters such as "%" and "?" must be escaped and URI that points to a package and must conform to RFC 2396.

For more info please read "Pack URIs in WPF"

I'm also learning WPF. This is what i have understood about Pack Uri in WPF till now.

对你的占有欲 2024-10-31 19:06:12

还要解释一下分号:

pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml

如果您想使用 Referenced dll 引用资源,您可以使用它。请记住,ReferencedAssembly 指的是程序集的名称。另请记住,如果将 ResourceFile.xaml 放置在 referencedAssembly 的根目录中,则应使用 component/ResourceFile.xaml 指定路径。因此您可以看到,通过 ReferencedAssembly 引用的每个文件都应始终相对于组件文件夹。例如
pack://application:,,,/MyCustomdll;component/MyResource.xaml。

pack://application:,,,/ReferencedAssembly;component/subfolder/ResourceFile.xaml

与上面指定的类似,如果资源放置在程序集中的子文件夹中,则需要再次引用相对于组件文件夹的子文件夹。

资料来源: http://www.abhisheksur.com/ 2010/04/pack-uri-to-reference-component.html

Explaining the semicolon too:

pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml

If you want to refer to the resource using the Referenced dll, you might use this. Remember the ReferencedAssembly refers to the name of the Assembly. Also remember if you place the ResourceFile.xaml in your root directory of referencedAssembly you should specify the path using component/ResourceFile.xaml. Therefore you can see, every file that is referenced through the ReferencedAssembly should always be relative to component folder. So for instance
pack://application:,,,/MyCustomdll;component/MyResource.xaml.

pack://application:,,,/ReferencedAssembly;component/subfolder/ResourceFile.xaml

Similar to one specified above, if the resource is placed within a subfolder within the assembly, you need to again reference that relative to component folder.

Source: http://www.abhisheksur.com/2010/04/pack-uri-to-reference-component.html

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