Don’t use Name as a Property for your own classes in Silverlight 2

Lately I discovered a change in Silverlight 2 (from beta 2) in the handling of names in XAML. If you create an object with a Name property, you cannot set it in XAML (not normally that is).

For example, you have this class:

public class Person
{
  public string Name { get; set; }

  public int Age { get; set; }
}

If you use it in XAML like this the Name property doesn’t get set:

<my:Person
           Name="jefke"
           Age="23">
</my:Person>

Instead XAML will create a reference called jefke pointing to this object.

This sucks of course because there are tons of objects out there that have a Name property, and now we cannot use them in XAML. This is also different from WPF, because there you can use a Name property, and use x:Name to set its namescope. The Name property will still get set normally; to make Name equivalent to x:Name you would use the RuntimeNamePropertyAttribute.