首先,我有一个风格的应用程序资源的资源,像这样:它TextBlock的风格将覆盖模板化父样式
<Style x:Key="ContentTextBlock" TargetType="FrameworkElement">
<Setter Property="TextBlock.HorizontalAlignment" Value="Center"/>
<Setter Property="TextBlock.VerticalAlignment" Value="Center"/>
<Setter Property="TextBlock.FontFamily" Value="Verdana"/>
<Setter Property="TextBlock.FontSize" Value="12"/>
<Setter Property="TextBlock.FontWeight" Value="Normal"/>
<Setter Property="TextBlock.Foreground" Value="Orange"/>
</Style>
我创建了有一个头一个自定义的控制和内容。 这是内容部分看起来像在自定义控制模板:
<ContentPresenter Content="{TemplateBinding Content}"
Style="{DynamicResource ContentTextBlock}">
</ContentPresenter>
我的问题是,如果我使用创建的控制,像这样:
<local:CutPage.Content>
<TextBlock>Header</TextBlock>
</local:CutPage.Content>
的字体大小,fontWeight设置,并且fontFamily得到重写通过TextBlock的显式或默认样式(我认为是这种情况,但我不确定)。我已经阅读了有关依赖性价值顺序优先顺序的文章,但我怎么能猜到什么是重写我的模板样式?我希望所有进入自定义控件的头元素都使用这些值。我应该怎么做?
P.S.有趣的是,一些风格制定者的工作(如垂直和水平居中文本),但其他人不!