ContentPresenter通常出現在ControlTemplate內,是用于显示Content属性的值
以下xaml代码的运行结果是Hello World,如果不用ContenPresenter,则不显示Hello World
<Button Content="Hello World">
<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter></ContentPresenter>
</ControlTemplate>
</Button.Template>
</Button>
Button控件的Template属性赋值
如果赋值为ControlTemplate类型的对象并放在Window的Resource中
<Window.Resources>
<ControlTemplate x:Key="BtnTemplate">
<Border BorderBrush="Blue"
BorderThickness="1"
Background="{TemplateBinding Background}"
CornerRadius="5">
<Grid>
<TextBlock
Text="{TemplateBinding ButtonBase.Content}"
VerticalAlignment="Center"