views:

747

answers:

3

In Silverlight (and I guess WPF) why are the properties x:name x:fieldmodifier x:uid the only ones with the prefix x.

I understand the x prefix is used to refer to the XML namespace but there are a number of other properties that do not use a prefix such as width. Identifying a control is such a common task it seems odd to require a prefix?

+2  A: 

Update: I’m sorry because I don't understand well the question (see the comment).

In silverlight and wpf the .net namespaces are associated to xml namespaces. The more common .net namespaces are a associated to the xml namespace "http://schemas.microsoft.com/winfx/2006/xaml/presentation". Then in the xaml root element there is this namespace definition:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

These means that the .net namespaces associated to "http://schemas.microsoft.com/winfx/2006/xaml/presentation" doesn't need prefix.

Here is a good explanation of xaml and namespaces.

DaniCE
Thanks but I understand that. Why not have x:name in one of the root namespaces so it doesnt need a prefix?
alexmac
alexmac: There are 2 namespaces here, the 'xaml' and the 'presentation' namespace. Every element is in one of these namespaces, but only one namespace can be the default one. If you change the xmlns declaration in the root element you can probably choose whichever default namespace you like
Gareth
Note that if you switch the 'xaml' namespace to be the default, every other element and attribute from the 'presentation' namespace will need an x: prefix
Gareth
It just seems odd that a commonly used thing like the name property couldnt be part of whichever namespace all the other properties are in? I guess this is probably to keep it seperate from the presentation and xaml namespaces so it could be used for other things
alexmac
A: 

One of:

  • Personal preference.
  • The implementation (class) of that project is in the same assembly as the XAML file.
  • Some fool decided to create his own name property.
Jonathan C Dickinson
I would appreciate the reason for downvotes. Particularily, reason 2 is 100% valid. Has anyone who has downvoted ever tested this? I doubt it.
Jonathan C Dickinson
+3  A: 

I think that the key point here is the difference between xaml and wpf / SL.

Xaml is really a object initialization language and is totally independent from wpf / SL. For example you can also use xaml to define workflows in WF. I think these is the reason to have the “pure” Xaml namespace’s differentiated from presentation namespaces.

DaniCE
Yep I agree, I think this is probably the reason it is done this way
alexmac