wpf http://schemas.microsoft.com/winfx/2006/xaml/presentation 定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25508755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
http://schemas.microsoft.com/winfx/2006/xaml/presentation definition
提问by abenci
When you create a new WpfApplication project in Visual Studio you get the following XAML. Copying and pasting the URL http://schemas.microsoft.com/winfx/2006/xaml/presentationinto the browser I expected to see the XSD file definition but I get an error. Why?
在 Visual Studio 中创建新的 WpfApplication 项目时,您将获得以下 XAML。将 URL http://schemas.microsoft.com/winfx/2006/xaml/presentation复制并粘贴到浏览器中,我希望看到 XSD 文件定义,但出现错误。为什么?
Thanks.
谢谢。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
回答by Moumit
The problem is most of wpf developer knows how it worksbut when you going to explain, it's become much difficult .. below is my try ... due to simplification it become large but i hope if you read to the end, you will understand how the definition thing works ..
问题是大多数 wpf 开发人员都知道它是如何工作的,但是当你要解释时,它变得非常困难..下面是我的尝试......由于简化它变得很大但我希望如果你读到最后,你会明白定义的东西是如何工作的..
Scenario:
设想:
I am a wpf beginner developer and searching for a wpf spinner on goggle. i got a link of font.awesome.wpf.. so i started to trying it. below code is written in document to add the spinner ..
我是一名 wpf 初学者开发人员,正在寻找护目镜上的 wpf 微调器。我得到了一个font.awesome.wpf的链接.. 所以我开始尝试它。下面的代码写在文档中以添加微调器..
<Window x:Class="DemoFontAwesome.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:fa="http://schemas.fontawesome.io/icons/"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="20">
<fa:ImageAwesome Icon="AlignCenter" Spin="False" Height="48" Width="48" />
</Grid>
</Window>
Wow great .... It's working fine !!! ...
哇太棒了......它工作正常!!!...
Suddenly!! i discover that i added a line there
突然!!我发现我在那里添加了一行
xmlns:fa="http://schemas.fontawesome.io/icons/"
Not something like
不像
xmlns:fa="clr-namespace:FontAwesome.WPF;assembly=FontAwesome.WPF"
then how visual studio knew which dllcontain the ImageAwesome class!!! ... I added only FontAwesome.WPF.dllthrough nuget ..nothing else i did.. no additional xsd or xml file is there.. The schema link(http://schemas.fontawesome.io/icons/) is not available ...then how??
...Strange!!
那么visual studio 如何知道哪些dll包含ImageAwesome 类!!!...我只FontAwesome.WPF.dll通过 nuget添加..我没有做其他任何事情..没有额外的 xsd 或 xml 文件在那里.. 架构链接(http://schemas.fontawesome.io/icons/)不可用......然后如何??...奇怪的!!
However after 1 hours i ended up with below code..
但是 1 小时后,我最终得到了以下代码..
<Window x:Class="DemoFontAwesome.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:fa="http://schemas.fontawesome.io/icons/"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<fa:CssClassNameConverter Mode="FromIconToString" x:Key="sdfsdf"></fa:CssClassNameConverter>
</ResourceDictionary>
</Window.Resources>
<Grid Margin="20">
<fa:ImageAwesome Icon="AlignCenter" Spin="False" Height="48" Width="48" />
</Grid>
</Window>
The noticable part is fa:ImageAwesomeand fa:CssClassNameConverterclasses... They are from different namespace(using code behind i already checked it).. and i did not specified one extra line to specify any of FontAwesome.WPFor FontAwesome.WPF.Convertersnamespace.. then how the magic going on!! ..
值得注意的部分是fa:ImageAwesome和fa:CssClassNameConverter类......它们来自different namespace(使用我已经检查过的代码背后的代码)......而且我没有指定额外的一行来指定任何一个FontAwesome.WPF或FontAwesome.WPF.Converters命名空间......那么魔法是如何发生的!..
Solution:
解决方案:
So i downloaded the source code of font.awesome.wpf.. and started search for the text http://schemas.fontawesome.io/icons/there ... and finally i found the below lines in assembly.csof font.awesome.wpf project..
所以我下载了font.awesome.wpf的源代码.. 并开始在http://schemas.fontawesome.io/icons/那里搜索文本......最后我在assembly.csfont.awesome.wpf 项目中找到了以下几行..
[assembly: AssemblyVersion("4.5.0.*")]
[assembly: AssemblyFileVersion("4.5.0.7")]
[assembly: XmlnsPrefix("http://schemas.fontawesome.io/icons/", "fa")]
[assembly: XmlnsDefinition("http://schemas.fontawesome.io/icons/", "FontAwesome.WPF")]
[assembly: XmlnsDefinition("http://schemas.fontawesome.io/icons/", "FontAwesome.WPF.Converters")]
And the whole thing (the magic trick!!) revealed to me ..
整件事(魔术!)向我揭示了..
In assembly.csfile the component defined the http://schemas.fontawesome.io/icons/namespace .. so when i add fontawesome.wpf dll ... visual studio got it's namespace definition using refection .. and so how vs knows where the fa tag refers to... So this is how it resolvedto me... :)
在assembly.cs文件中,组件定义了http://schemas.fontawesome.io/icons/命名空间 .. 所以当我添加 fontawesome.wpf dll 时......visual studio 使用反射得到了它的命名空间定义 .. 所以 vs 如何知道fa tag refers to......所以这就是它如何解决我.. .:)
Some theory
一些理论
XML namespace name doesn't match any particular .NET namespace. There are a couple of reasons the creators of XAML chose this design. By convention, XML namespaces are often uniform resource identifiers (URIs) as they are here. These URIs look like they point to a location on the Web, but they don't. The URI format is used because it makes it unlikely that different organizations will inadvertently create different XML-based languages with the same namespace. Because the domain schemas.microsoft.com is owned by Microsoft, only Microsoft will use it in an XML namespace name.
The other reason that there isn't a one-to-one mapping between the XML namespaces used in XAML and .NET namespaces is because it would significantly complicate your XAML documents. The problem here is that WPF encompasses well over a dozen namespaces (all of which start with System.Windows). If each .NET namespace had a different XML namespace, you'd need to specify the right namespace for each and every control you use, which quickly gets messy. Instead, the creators of WPF chose to combine all of these .NET namespaces into a single XML namespace. This works because within the different .NET namespaces that are part of WPF, there aren't any classes that have the same name. The namespace information allows the XAML parser to find the right class. For example, when it looks at the Window and Grid elements, it sees that they are placed in the default WPF namespace. It then searches the corresponding .NET namespaces until it finds System.Windows.Window and System. Windows.Controls.Grid
XML 命名空间名称与任何特定的 .NET 命名空间都不匹配。XAML 的创建者选择这种设计有几个原因。按照惯例,XML 命名空间通常是统一资源标识符 (URI),就像它们在这里一样。这些 URI 看起来像是指向 Web 上的某个位置,但实际上并非如此。使用 URI 格式是因为它不太可能使不同的组织无意中创建具有相同名称空间的不同的基于 XML 的语言。由于域 schemas.microsoft.com 归 Microsoft 所有,因此只有 Microsoft 会在 XML 命名空间名称中使用它。
在 XAML 和 .NET 命名空间中使用的 XML 命名空间之间没有一对一映射的另一个原因是,它会使您的 XAML 文档显着复杂化。这里的问题是 WPF 包含十多个命名空间(所有命名空间都以 System.Windows 开头)。如果每个 .NET 命名空间都有不同的 XML 命名空间,则需要为使用的每个控件指定正确的命名空间,这很快就会变得混乱。相反,WPF 的创建者选择将所有这些 .NET 命名空间组合到一个 XML 命名空间中。这是有效的,因为在作为 WPF 一部分的不同 .NET 命名空间中,没有任何具有相同名称的类。命名空间信息允许 XAML 解析器找到正确的类。例如,当它查看 Window 和 Grid 元素时,它看到它们被放置在默认的 WPF 命名空间中。然后搜索相应的 .NET 命名空间,直到找到 System.Windows.Window 和 System。Windows.Controls.Grid
回答by Abel
A namespace is a URI (a URN or a URL), but a URI is not always a URL. The URI used for namespaces is meant to uniquely identify names to prevent clashed. The XML Namespaces Working Group at the time decided to use a technique already know to uniquely identify things: URIs.
命名空间是一个 URI(一个 URN 或一个 URL),但一个 URI 并不总是一个 URL。用于命名空间的 URI 旨在唯一标识名称以防止冲突。XML 命名空间工作组当时决定使用一种已知的技术来唯一标识事物:URI。
As a result, many people think it should actually point to something real. Occasionally that is true, but more often it is not, and it is not meant to be. It is an identitifier, not a location.
因此,许多人认为它实际上应该指向一些真实的东西。有时这是真的,但更多时候不是,也不是故意的。它是一个标识符,而不是一个位置。
In the case of schemas, it is can be used to denote the target namespace, which is the namespace that must be used in documents that need to validated against the schema. To obtain the schema, you will have to ask the vendor. In this case, the schema can be found at a location similar or equal to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas, look for wpfe.xsd(however, to confuse matters more, Microsoft has decided to create an alias for the target namespace, which is why you will not see the same namespace you mentioned).
在模式的情况下,它可用于表示目标名称空间,即必须在需要针对模式进行验证的文档中使用的名称空间。要获得架构,您必须询问供应商。在这种情况下,可以在类似于或等于 的位置找到架构C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas,查找wpfe.xsd(但是,更令人困惑的是,Microsoft 已决定为目标命名空间创建别名,这就是为什么您不会看到与您相同的命名空间的原因)提及)。

