#177 – A Content Presenter Is a Placeholder for a Content Control’s Content
January 5, 2011 Leave a comment
A content control (ContentControl) in WPF is a control that displays a single piece of content. The control will have a control template (Template property) that describes the specific visual elements that make up the control. Somewhere in that control template will be a content presenter (ContentPresenter), which indicates the spot in the control to display the actual content.
You can think of the ContentPresenter as a little pointer that says “put your content here”.
Below is the default control template for a Label control as an example. The control template includes a ContentPresenter inside a Border.
<ControlTemplate TargetType="{x:Type Label}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>