Indicates which property of a type is the XAML content property. A XAML processor uses this information when processing XAML child elements of XAML representations of the attributed type.
The ContentPropertyAttribute attribute has these types of members:
The ContentPropertyAttribute attribute has these constructors.
|ContentPropertyAttribute||Initializes a new instance of the ContentPropertyAttribute class.|
The ContentPropertyAttribute attribute has these fields.
Gets the name of the property that is the declared content property.
The ContentPropertyAttribute attribute inherits methods from the Object class.
This attribute is used to identify that a specific property of the attributed type should be considered the XAML content property, when interpreted by XAML parsers and other XAML framework code. The purpose of a XAML content property is that it provides a XAML syntax shorthand that can omit property element markup for that property. The removal of property elements facilitates a more natural parent-children form in XAML markup. For more info on XAML content properties, see "XAML content properties" section of Basic XAML syntax guide.
An example of a class in the default Windows Runtime XAML vocabulary that has ContentPropertyAttribute applied is Panel. The property Children on the Panel is identified as the XAML content property as defined by the ContentPropertyAttribute and its Name value. The content property information is inherited by all derived types of Panel, such as Grid and Canvas and StackPanel.
This code approximates how Panel applies ContentPropertyAttribute in C# (the true definition is applied in native code, this is for illustration only):
<StackPanel> <StackPanel.Children> <TextBlock>Testing content attribute</TextBlock> </StackPanel.Children> </StackPanel>
The above is equivalent to this more readable XAML:
When parsed by a XAML parser, the parser knows through the ContentPropertyAttribute applied on Panel that any content found within the body of a StackPanel tag should be used to set the value of Children on the created StackPanel instance.
Another prominent example of ContentPropertyAttribute in action can be seen on the TextBlock class. TextBlock uses Inlines as its content property, and the default inline class Run uses Text as its content property. In combination, the content properties enable a simple inline syntax such as
<TextBlock>Hello</TextBlock>, even though the object graph created by this XAML is more complex and is also capable of supporting multiple explicit inline elements if desired.
Minimum supported client
Minimum supported server
|Windows Server 2012|
Build date: 12/4/2012