为什么 XAML 命名空间是 URL?
在代码顶部的 Silverlight/WPF xaml 中,您有命名空间/导入类型声明。我可以很容易地理解这些声明如何指向程序集,以便可以从中加载类型等。我不明白的是(到目前为止我还没有真正考虑过)这些命名空间在指向某个 url 时如何工作,例如,
http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit
查看此 URL 会给我一个错误,因此不会告诉我任何信息。
In Silverlight/WPF xaml at the top of the code you have your namespace/import type declarations. I can easily understand how these declarations can point to an assembly so that the types etc can be loaded from it. What I don't understand (and what I haven't really thought about up to now) is how these namespaces work when they point to a url, e.g.
http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit
Looking at this URL gives me an error so doesn't tell me anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码中有可以在代码中使用的属性将 Uri 映射到代码命名空间的引用程序集的属性:
您可以包含多个这些属性(通常在
AssemblyInfo.cs
中),从而允许 Xaml 中的单个 Uri 命名空间引用多个代码命名空间。这使得您的命名空间声明更加紧凑(因为您可以省略程序集名称)。它还允许您在不破坏标记的情况下灵活地重新组织引用的程序集中的命名空间。
编辑:例如,如果您将 Reflector 指向
PresentationCore
程序集,您可以在程序集级别看到诸如此类的属性:这就是 Uri 导入映射到代码的方式命名空间。
There's an attribute you can use in the code of your referenced assembly that maps a Uri to your code namespaces:
You can include multiple of these attributes, typically in your
AssemblyInfo.cs
, allowing multiple code namespaces to be referenced by a single Uri namespace in Xaml.This makes your namespace declarations more compact (since you can omit the assembly name). It also allows you some flexibility in reorganizing namespaces in the referenced assembly without breaking your markup.
EDIT: for example, if you point Reflector at the
PresentationCore
assembly, you can see attributes such as this at the assembly level:This is how the Uri import gets mapped to code namespaces.
据我所知,它们只是不符合惯例的 URL,任何唯一标识符都可以。
如果您检查 HTML 文档类型,它们是完全相同的,就像没有实际加载一样:) 例如: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd 或 http://www.w3.org/TR/html4/strict.dtd
虽然这些网址上没有任何内容,但没有任何意义,如果有一些就好了实际参考...
As far as I know they are URLs only out of convention, any unique identifier would do.
If you check HTML doctypes they are exactly the same, as in not actually loading :) For example: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd or http://www.w3.org/TR/html4/strict.dtd
It makes no sense why isn't anything on these URLs though, would be nice to have some actual references...