17

My understanding of x:Name vs Name is that some controls have a Name property, that is basically the same as setting x:Name.

Is there an advantage to using Name when it is available over x:Name?

Here's my reference for understanding x:Name vs Name.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Chris Nicol
  • 10,256
  • 7
  • 39
  • 49
  • Sorry ... I did search for this question as I was sure it must have been asked already, but I couldn't find it. – Chris Nicol Dec 18 '09 at 19:59

3 Answers3

12

For any that has stumbled upon this question ... here's is a very detailed answer. Thanks to Taylor L for pointing me in the right direction.

Community
  • 1
  • 1
Chris Nicol
  • 10,256
  • 7
  • 39
  • 49
7

If Name is available as a property on the class, Name and x:Name can be used interchangeably as attributes, but an error will result if both are specified on the same element.

Source: x:Name Attribute

In other words, it makes no difference which one you use; just don't use both on the same element.

Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
  • 4
    Sometimes it makes a difference: http://stackoverflow.com/questions/1380112/why-cant-i-use-the-name-attribute-on-usercontrol-in-the-same-assembly – Karsten May 17 '11 at 07:55
7

You're safer using x:Name because it works all the time, where as Name depends on the particular control implementation.

Jim Wallace
  • 1,006
  • 8
  • 21