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.


Comments (1) -

October 24. 2008 12:29 PM

This is actually a bug reported from Beta 2 by Rob Eisenberg, but was around since "Silverlight 1.1".  For awhile, I had a thread on the Silverlight forums about bugs in the XAML parser for Silverlight.  Silverlight's XAML format is such a crippled version of XAML as a whole.  It doesn't even make sense to call it XAML -- you can't actually X-tend it!  Silverlight XAML is "XAML WITHOUT THE X".  By the way, I hate your captcha system.  I tried a handful of times.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Download the U2U brochure

Download Brochure

Receive the U2U Newsletter. Submit your email address:
 
 


 


Search

rss  RSS

Recent posts

None

Archive