What is ContentPropertyAttribute?
ContentPropertyAttribute is an attribute that a class author places on the class to specify the property that is the ContentProperty. As an example, here's part of the declaration of the Style class:
[ContentPropertyAttribute("Setters")]
public class Style : DispatcherObject, INameScope, IAddChild
When a property is the ContentProperty for a class, it becomes the property that takes the content of the element, as written in XAML. In that way, it provides a XAML shortcut.
For example, you may have the following XAML:
<Style TargetType="TextBox">
<Style.Setters>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="25"/>
</Style.Setters>
<Style.Triggers>
<!-- Triggers go here-->
</Style.Triggers>
</Style>
The above is equivalent to the following:
<Style TargetType="TextBox">
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="25"/>
<Style.Triggers>
<!-- Triggers go here-->
</Style.Triggers>
</Style>
Notice that the <Style.Setters/> tags can be omitted because Setters is the ContentProperty.
For your convenience, here’s the list of properties with the attribute set (thanks to our teammate Michael for generating the list). The subclasses are not listed here but these are applicable to the subclasses as well (e.g. ListBox is an ItemsControl so the Items property is the ContentProperty for ListBox).
AccessText.Text |
AdornedElementPlaceholder.Child |
AnchoredBlock.Blocks |
ArrayExtension.Items |
BeginStoryboard.Storyboard |
BitmapEffectGroup.Children |
BlockUIContainer.Child |
ContentControl.Content |
DataTrigger.Setters |
Decorator.Child |
DocumentViewerBase.Document |
DrawingGroup.Children |
EventTrigger.Actions |
FixedDocument.Pages |
FixedDocumentSequence.References |
FixedPage.Children |
FlowDocument.Blocks |
FlowDocumentReader.Document |
FlowDocumentScrollViewer.Document |
Frame.Content |
FrameworkTemplate.VisualTree |
GeneralTransformGroup.Children |
GeometryGroup.Children |
GradientBrush.GradientStops |
GridView.Columns |
GridViewColumn.Header |
InkCanvas.Children |
InlineUIContainer.Child |
ItemsControl.Items |
List.ListItems |
ListItem.Blocks |
MaterialGroup.Children |
Model3DGroup.Children |
ModelVisual3D.Children |
MultiBinding.Bindings |
MultiDataTrigger.Setters |
MultiTrigger.Setters |
NavigationWindow.Content |
Page.Content |
PageContent.Child |
Panel.Children |
Paragraph.Inlines |
PathFigure.Segments |
PathGeometry.Figures |
Popup.Child |
PriorityBinding.Bindings |
RichTextBox.Document |
Run.Text |
Section.Blocks |
Span.Inlines |
Style.Setters |
Table.RowGroups |
TableCell.Blocks |
TableRow.Cells |
TableRowGroup.Rows |
TextBlock.Inlines |
TextBox.Text |
ThicknessAnimationUsingKeyFrames.KeyFrames |
ToolBarTray.ToolBars |
Transform3DGroup.Children |
TransformGroup.Children |
Trigger.Setters |
VectorAnimationUsingKeyFrames.KeyFrames |
Viewport3D.Children |
Viewport3DVisual.Children |
XmlDataProvider.XmlSerializer |
Happy Holidays from the WPF SDK team!
Tina
About Us
We are the Windows Presentation Foundation SDK writers and editors.
Comments
Anonymous
October 19, 2008
Вводное руководство по WPF - Часть I (XAML) Вводное руководство по WPF - Часть II (Layout) Вводное руководствоAnonymous
October 28, 2008
Вводное руководство по WPF - Часть I (XAML) Вводное руководство по WPF - Часть II (Layout) Вводное руководство