(X) Hide this Upcoming webinar by Brian Noyes: Querying and Updating Data From Silverlight Clients with WCF RIA Services. February 2nd, 10 am PST (see your local time)
Full webinar info | Register | Read WCF RIA Services Article series by Brian Noyes
Become a member to receive all webinar news by email, or follow all webinar news on Twitter | Facebook | LinkedIn
Skip Navigation LinksHome / Tips / View Tip

Tip: How to declare child elements inside your control in XAML?

+ Add to SilverlightShow Favorites
1 comments   /   posted by Denislav Savkov on Sep 05, 2008
(0 votes)
Categories: Controls and UI

All child elements in fact are properties. To indicate which property accepts the child element as its value you must specify the ContentProperty attribute of the class.

C#
[ContentProperty("PropertyName")]
public class SomeClass
{
    ...
    public PropertyType PropertyName {get;set;}
    ...
}
 
XAML
<SomeClass x:Name="someClassInstance">
    Value
</SomeClass>

This way the last declaration corresponds to the following C# code

C#

someClassInstance.PropertyName = Value;
That's it!

 

 

Share


Comments

Comments RSS RSS
  • RE: Tip: How to declare child elements inside your control in XAML?  

    posted by Dave on Jan 05, 2009 19:34

    This doesn't seem work with UserControls. Complains that "'System.Windows.Controls.UserControl.ContentProperty' is a 'field' but is used like a 'type'"

Add Comment

 
 

   
  
  
   
Please add 6 and 3 and type the answer here: