Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x:key keyword in WPF

Tags:

wpf

xaml

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?

like image 667
nimisha Avatar asked Sep 20 '13 18:09

nimisha


1 Answers

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.

like image 106
Reed Copsey Avatar answered Nov 03 '22 23:11

Reed Copsey