Skip to main content
/_layouts/images/titlegraphic.gif

Peter Himschoot's Windows Foundation Trilogy

Go Search
Peter Himschoot's Windows Foundation Trilogy
U2U Website
  

Talking about .NET, Windows Presentation Foundation, Workflow Foundation and Communication Foundation

Peter Himschoot's Windows Foundation Trilogy > Posts > Don’t use Name as a Property for your own classes in Silverlight 2
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

XAML WITHOUT THE X

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.
at 24/10/2008 22:29

Add Comment

Title


Body *


Attachments
Captcha

Enter the code shown above: *

(Note: If you cannot read the numbers in the above
image, reload the page to generate a new one.)