title: In a button's control template, how can I set the color of contained text?
body: <p>Using Silverlight 4 &amp; WPF 4, I'm trying to create a button style that alters the text color of any contained text when the button is mouseover'd. Since I'm trying to make this compatible with both Silverlight &amp; WPF, I'm using the visual state manager:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type Button}"&gt;
  &lt;Setter Property="Template"&gt;
      &lt;Setter.Value&gt;
          &lt;ControlTemplate TargetType="Button"&gt;
              &lt;Border x:Name="outerBorder" CornerRadius="4" BorderThickness="1" BorderBrush="#FF757679"&gt;
                  &lt;VisualStateManager.VisualStateGroups&gt;
                      &lt;VisualStateGroup x:Name="CommonStates"&gt;
                          &lt;VisualState x:Name="Normal" /&gt;
                          &lt;VisualState x:Name="MouseOver"&gt;
                              &lt;Storyboard&gt;
                                  &lt;ColorAnimation Duration="0" To="#FFFEFEFE"
                                                  Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)"
                                                  Storyboard.TargetName="contentPresenter"/&gt; 
                              &lt;/Storyboard&gt;
                          &lt;/VisualState&gt;
                      &lt;/VisualStateGroup&gt;
                  &lt;/VisualStateManager.VisualStateGroups&gt;
                  &lt;Grid&gt;
                      &lt;Border x:Name="Background" CornerRadius="3" BorderThickness="1" BorderBrush="Transparent"&gt;
                          &lt;Grid&gt;
                              &lt;ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}"/&gt;
                          &lt;/Grid&gt;
                      &lt;/Border&gt;
                  &lt;/Grid&gt;
              &lt;/Border&gt;
          &lt;/ControlTemplate&gt;
      &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  </code></pre>
  
  <p></p>
  
  <p>Since this is a template for a regular old button, I know there's no guarantee that there even is a textblock inside of it, and at first I wasn't sure this was even possible. Curiously, the text color <em>does</em> change if the button is declared like:</p>
  
  <pre><code>&lt;Button Content="Hello, World!" /&gt;
  </code></pre>
  
  <p>but it <em>does not</em> change if the button is declared like:</p>
  
  <pre><code>&lt;Button&gt;
      &lt;TextBlock Text="Hello, World!" /&gt; &lt;!-- Same result with &lt;TextBlock&gt;Hello, World &lt;/TextBlock&gt; --&gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p>Even though the visual tree (when inspected in snoop) is identical (Button -> ContentPresenter -> TextBlock), with the caveat that the textblock created in the 1st version has it's data context set to "Hello, World", whereas the textblock in the second version merely has its text property set. I'm presuming this has something to do with the order of control creation (the first version the button creates the TextBlock, in the second version the textblock might be created first? Really not sure on this).</p>
  
  <p>In the course of researching this, I've seen some solutions that work in Silverlight (like replacing the ContentPresenter with a ContentControl), but that won't work in WPF (program actually crashes).</p>
  
  <p>Since this is in the button's control template, and I'd like to use the VSM if possible, I think that also rules out explicitly changing the Button's own Foreground property (I don't know how I would access that from within the template?)</p>
  
  <p>I'd really appreciate any help, advice anyone could give.</p>