Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Two Questions

1. In XAML, why do we use x: before a specific name or after the xmlns namespace keyword like..


xmlns : x = "http://abc"

and

<rectangle x:name="abc" xmlns:x="#unknown">

===========================================================

2. why the namespace in XAML is some web address starting with http:// and why not some identifier like in C++ as "using namespace myNameSpace"

why do we have namespace in XAML something starting with "http://"
Posted

For the first question, x is a prefix (~alias) for the namespace which can be used in the xaml. For more info see for example: http://msdn.microsoft.com/en-us/library/ms747086.aspx[^]

Don't know the actual reason for the second question, but I'd guess it's because the syntax conforms the XML namespace declaration. However, namespaces starting http aren't always used. For example if you refer to a namespace in the current project, the syntax is different. For example:
xmlns:MyNamespace="clr-namespace:MyProject.Controls;assembly=MyProject">
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Aug-11 3:15am    
OK, you started to answer -- correctly, but did not complete the second question -- my 5. I answered the second one and added some explanation of the first one -- please see.
Teamwork! :-)
--SA
Wendelius 6-Aug-11 3:32am    
Yep, occasionally I have time to visit these forums but not very often. This time I asked a question about a corrupted win 7 installation so I went through few questions at the same time.

Nice to hear from you :)
Nika answered first question; I'm answering the second one.

The namespace schema "http://" comes not from from XAML specifically, but from XML. The reason is the possibility of creation of world-unique identifiers (XML tags, attributes) through world uniqueness of the name space. The XML name space can be created based on really existing URL. As our world has the system of unique domain names provided hierarchically by Internet authority organization, every company or other organization gets one or more world-unique domain names. The part of URL after domain name is supported by the organization via its Web site, so anyone can locate the resource having the same URL as the XML name schema.

Inside the XML, name spaces are denoted by the unique prefix (alias) and the uniqueness is controlled by the XML parser. The prefix itself has the scope of a single XML document, but the corresponding namespace can be world unique. This hierarchy makes every namespace-based XML identifier world-unique, which can be validated.

As to .NET namespaces, such world uniqueness of name spaces is not required. Instead, the assemblies themselves can get "almost" unique names through the mechanism of string naming, but this is already quite a different story…

—SA
 
Share this answer
 
v2
Comments
Wendelius 6-Aug-11 3:30am    
Good answer, my 5
Sergey Alexandrovich Kryukov 6-Aug-11 3:40am    
Thank you, Mika.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900