1
Vote

The ContentPropertyAttribute should be mentioned

description

In WPF every class can be marked with the ContentPropertyAttribute to define a Default-Property that is set via XAML if the content inside the element isn't explicitly assigned to a property by Property-Element-Syntax. E.g.:
 
[ContentProperty("FirstName")]
public class Friend{
public string FirstName{get;set;}
}
 
e.g. Instead of
<Friend>
<Friend.FirstName>
 Thomas
</Friend.FirstName>
<Friend>
 
can be set
 
<Friend>
Thomas
<Friend>
 
In Silverlight that won't work. The ContentPropertyAttribute is there, but it doesn't work for custom Types. Unfortunately this isn't documented anywhere in the Silverlight-documents. :-)

comments

linksaussen wrote Jun 17, 2009 at 2:26 PM

Unfortunately this isn't documented anywhere in the Silverlight-documents
I was wrong, it is. :-)
So Silverlight XAML-Parser vs. WPF-XAML-Parser:
In WPF
<Friend>
Thomas
<Friend>
works with the ContentPropertyAttribute set, but in Silverlight an element cannot contain plain text as content. So I played around and by using the System-Namespace mapped to the sys-Alias, this works in Silverlight
<Friend>
<sys:String>
Thomas
</sys:String>
<Friend>

Fazit: The ContentPropertyAtrribute is working correctly, but it differs that in Silverlight an element cannot contain plain text.

wrote Feb 14, 2013 at 3:20 AM