Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does x: stand for in x:key and x:name ? Why the colon and why not y:?

Tags:

wpf

xaml

This is confusing to me. Why do we have to use x:Key= and x:Name= in place of key= and name=?

Where does this x come from?

Thanks!

like image 485
Sylvain Rodrigue Avatar asked Dec 09 '22 15:12

Sylvain Rodrigue


2 Answers

The 'X' is an alias for an imported namespace (See the declaration of your XAML).

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

so when you type x, you use resources from that defined namespace. Actually, Name and Key are defined in the xaml namespace.

like image 200
Myrtle Avatar answered Dec 11 '22 09:12

Myrtle


The name and key properties are defined within a namespace to avoid clashing with properties of the same name defined on the controls I believe.

like image 34
BenjaminPaul Avatar answered Dec 11 '22 07:12

BenjaminPaul