为什么会有作为 URL 的 XAML 命名空间? [英] Why are there XAML namespaces that are URLS?

查看:21
本文介绍了为什么会有作为 URL 的 XAML 命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在代码顶部的 Silverlight/WPF xaml 中,您拥有命名空间/导入类型声明.我可以很容易地理解这些声明如何指向一个程序集,以便可以从中加载类型等.我不明白(到目前为止我还没有真正考虑过)这些命名空间在它们指向一个 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

查看此 URL 给我一个错误,所以没有告诉我任何信息.

Looking at this URL gives me an error so doesn't tell me anything.

推荐答案

这里有 可以在引用程序集的代码中使用的属性,将 Uri 映射到代码命名空间:

There's an attribute you can use in the code of your referenced assembly that maps a Uri to your code namespaces:

[XmlnsDefinitionAttribute("http://yournamespace/", "Your.Assembly.Namespace")]

您可以包含多个这些属性,通常在 AssemblyInfo.cs 中,允许 Xaml 中的单个 Uri 命名空间引用多个代码命名空间.

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.

例如,如果您将 Reflector 指向 PresentationCore 程序集,您可以在程序集级别看到如下属性:

for example, if you point Reflector at the PresentationCore assembly, you can see attributes such as this at the assembly level:

[assembly: 
    XmlnsDefinition( "http://schemas.microsoft.com/netfx/2007/xaml/presentation"
                   , "System.Windows.Ink") ]

这就是 Uri 导入映射到代码命名空间的方式.

This is how the Uri import gets mapped to code namespaces.

这篇关于为什么会有作为 URL 的 XAML 命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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