Sometimes it seems that the Name and x:Name attributes are interchangeable. We can refer both Name and x:Name of a Framework element in XAML. But in case of x:key, WPF not providing "key" keyword like Name. Both Name and x:Name are for same purpose. Name would be available without typing x:. Why we are not able to use key like this in XAML?
There is actually a Name
property on FrameworkElemnet
. The x:Name
Directive actually will map to the Name
property because of a RuntimeNamePropertyAttribute
that causes the parser to perform the mapping. These are actually not 100% interchangable - it's more of a one-way mapping, where the parser sets the FrameworkElement.Name
property to match the value specified in x:Name
.
No such property or attribute exists for "Key", so the x:Key
directive can't map through to a property in the same way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With