什么是 Uri Pack,以及“:,,,”在位图图像中?
我添加 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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:///
andsiteoforigin:///
. Theapplication:///
authority identifies resource files, content files. Thesiteoforigin:///
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 toRFC 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.
还要解释一下分号:
如果您想使用 Referenced dll 引用资源,您可以使用它。请记住,ReferencedAssembly 指的是程序集的名称。另请记住,如果将 ResourceFile.xaml 放置在 referencedAssembly 的根目录中,则应使用 component/ResourceFile.xaml 指定路径。因此您可以看到,通过 ReferencedAssembly 引用的每个文件都应始终相对于组件文件夹。例如
pack://application:,,,/MyCustomdll;component/MyResource.xaml。
与上面指定的类似,如果资源放置在程序集中的子文件夹中,则需要再次引用相对于组件文件夹的子文件夹。
资料来源: http://www.abhisheksur.com/ 2010/04/pack-uri-to-reference-component.html
Explaining the semicolon too:
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.
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