ContentPresenter.Content Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the data that is used to generate the child elements of a ContentPresenter.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<ContentPresenter Content="{Binding}"/>
Property Value
Type: System.ObjectThe data that is used to generate the child elements. The default is null.
Dependency property identifier field: ContentProperty
When you put a ContentPresenter in the ControlTemplate of a ContentControl, it automatically displays the Content of the templated control. For example, if you put a ContentPresenter in a ControlTemplate of a Button, the Content property of the ContentPresenter is implicitly bound to the Content of the Button that uses the ControlTemplate.
The XAML usage shown is the necessary when a ContentPresenter is part of a DataTemplate. When a ContentPresenter is part of a ControlTemplate, you do not need to template bind the Content property.
The following example creates a ControlTemplate for Button and uses a ContentPresenter to display the content of the Button.
<StackPanel> <StackPanel.Resources> <Style x:Key="newButtonTemplate" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Rectangle Fill="{TemplateBinding Background}" /> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </StackPanel.Resources> <TextBlock Text="ContentPresenter Demonstration" Margin="0,20,10,20" FontFamily="Verdana" FontSize="18" FontWeight="Bold" Foreground="#FF5C9AC9" Grid.Row="0" /> <Button Content="default button" Width="200" Margin="7" Click="Button_Click"/> <Button Content="button with control template" Style="{StaticResource newButtonTemplate}" Margin="7" Background="LightGray" Width="200" Click="Button_Click"/> <Button Content="another button with control template" Style="{StaticResource newButtonTemplate}" Margin="7" Background="LightBlue" Width="200" Click="Button_Click"/> </StackPanel>