(X) Hide this
    • Login
    • Join
      • Say No Bots Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

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

(0 votes)
Denislav Savkov
>
Denislav Savkov
Joined Feb 11, 2008
Articles:   14
Comments:   6
More Articles
1 comments   /   posted on Sep 05, 2008
Tags:   xaml , denislav-savkov
Categories:   General

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!

 

 


Subscribe

Comments

  • -_-

    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

Login to comment:
  *      *       
Login with Facebook