You can do what you are looking for without using ContentControl and just using VisualStateManager
I can, of course, change the color of the text by editing the style, but this is not useful, because it is in states that are interesting to me in editing.
So, say, for example, to apply the new Foreground color to the text of your Button : MouseOver ,
- First, Blend does not create a
Brush resource for Button.MouseOver.Foreground when editing a Button template.
so create it. (Just add the following line along with other brush resources)
<SolidColorBrush x:Key="Button.MouseOver.Foreground" Color="Tomato" />
- Now we can apply the
Storyboard to TextElement.Foreground contentPresenter .
so your VSM will look like this:
<VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="MouseOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(TextElement.Foreground)"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <SolidColorBrush Color="{Binding Source={StaticResource Button.MouseOver.Foreground}, Path=Color}" /> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Pressed"/> <VisualState x:Name="Disabled"/> </VisualStateGroup> </VisualStateManager.VisualStateGroups>
and what is he.
Notice what we are doing here will only be fine when the Content from the Button is just text, but since your use is mentioned in your question, you should be fine.
Sidenote:
You can do the same just by switching the contentPresenter to TextBlock in the ControlTemplate .
If you need Foreground for any Content for Button , then ye just switch the contentPresenter to ContentControl , and you can still open your VSM layout in a very similar way.
Update
To switch the contentPresenter to a ContentControl , in your ControlTemplate simply switch the actual item to a new one.
<ControlTemplate TargetType="{x:Type Button}"> ... <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/> ... </ControlTemplate>
in
<ControlTemplate TargetType="{x:Type Button}"> ... <ContentControl x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}"/> ... </ControlTemplate>
you will need to update your properties accordingly, for example, ContentControl does not support RecognizesAccessKeys , and it also needs Content="{TemplateBinding Content}" to actually display the content. With contentPresenter Content property is set implicitly.