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

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

问题描述

在代码顶部的Silverlight/WPF xaml中,您具有名称空间/导入类型声明.我很容易理解这些声明如何指向程序集,以便可以从中加载类型等.我不了解的(以及到目前为止我还没有真正想到的)是这些命名空间在指向某个网址(例如

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天全站免登陆