The title says it all. Sometimes it seems that the Name
and x:Name
attributes are interchangeable.
So, what are the definitive differences
I always use the x:Name variant. I have no idea if this affects any performance, I just find it easier for the following reason. If you have your own usercontrols that reside in another assembly just the "Name" property won't always suffice. This makes it easier to just stick too the x:Name property.
One of the answers is that x:name is to be used inside different program languages such as c# and name is to be used for the framework. Honestly that is what it sounds like to me.
Name
can also be set using property element syntax with inner text, but that is uncommon. In contrast, x:Name
cannot be set in XAML
property element syntax, or in code using SetValue
; it can only be set using attribute syntax on objects because it is a directive.
If Name
is available as a property on the class, Name
and x:Name
can be used interchangeably as attributes, but a parse exception will result if both are specified on the same element. If the XAML is markup compiled, the exception will occur on the markup compile, otherwise it occurs on load.