I have a button style like this
<Style x:Key="NormalButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="ContentSite">
<Grid x:Name="ContainerGrid">
<ContentPresenter x:Name="Presenter" Style="{DynamicResource NormalButtonTextStyle}"/>
...
Where the style for the ContentPresenter is
<Style x:Key="NormalButtonTextStyle" BasedOn="{StaticResource DefaultFontStyle}">
<Setter Property="TextElement.Foreground" Value="{DynamicResource NormalTextOnDarkBackgroundBrush}" />
...
So then I defined my button like this
<Button Style="{StaticResource NormalButtonStyle}">
<Button.Content>
<TextBlock Text="Cancel"/>
...
But the TextBlock does not end up with the NormalButtonTextStyle
style. I inspected the elements during runtime and the content presenter definitely has the right text foreground, but then the child TextBlock ends up inheriting from something entirely different and gets a foreground of ControlTextBrush
.
Am I misunderstanding how styles are applied to child elements? How am I supposed to define the button so that the style is applied correctly?
ContentPresenter
style insideControlTemplate.Resources
? – XAMlMAX