title: Problem setting Foreground with Visual State Manager
body: <p>I have a WPF application, and I am attempting to style a TextBox using the .Net v4 Visual State Manager.  Specifically, I am attempting to set the colors of the Foreground and Background for the MouseOver state.</p>
  
  <p>What is happening is that, while the background and border are changing perfectly, the foreground is not.  If the brushes that I am using get their color via a StaticResource, then the foreground does not change at all.  If the brushes that I am using get their color via a DynamicResource, then when I mouse over a TextBox, the foreground of all TextBoxes change.  Clearly, either I'm doing something wrong, or what I want to do is simply not possible with VSM (which would be rather disappointing).</p>
  
  <p>Here are the resources that I am using:</p>
  
  <pre><code>&lt;Color x:Key="ControlBackgroundColor" R="178" G="178" B="178" A="255" /&gt;
  &lt;Color x:Key="ControlForegroundColor" R="0" G="0" B="0" A="255" /&gt;
  &lt;Color x:Key="BorderColor" R="127" G="127" B="127" A="255" /&gt;
  &lt;Color x:Key="MouseOverControlBackgroundColor" R="0" G="0" B="0" A="255" /&gt;
  &lt;Color x:Key="MouseOverControlForegroundColor" R="255" G="255" B="255" A="255" /&gt;
  &lt;Color x:Key="MouseOverBorderColor" R="178" G="178" B="178" A="255" /&gt;
  
  &lt;SolidColorBrush PresentationOptions:Freeze="True" x:Key="ControlBackgroundBrush" Color="{DynamicResource ControlBackgroundColor}" /&gt;
  &lt;SolidColorBrush PresentationOptions:Freeze="True" x:Key="ControlForegroundBrush" Color="{DynamicResource ControlForegroundColor}" /&gt;
  &lt;SolidColorBrush PresentationOptions:Freeze="True" x:Key="BorderBrush" Color="{DynamicResource BorderColor}" /&gt;
  
  &lt;SolidColorBrush PresentationOptions:Freeze="True" x:Key="MouseOverControlBackgroundBrush" Color="{DynamicResource MouseOverControlBackgroundColor}" /&gt;
  &lt;SolidColorBrush PresentationOptions:Freeze="True" x:Key="MouseOverControlForegroundBrush" Color="{DynamicResource MouseOverControlForegroundColor}" /&gt;
  &lt;SolidColorBrush PresentationOptions:Freeze="True" x:Key="MouseOverBorderBrush" Color="{DynamicResource MouseOverBorderColor}" /&gt;
  
  &lt;Style TargetType="{x:Type TextBox}" &gt;
      &lt;Setter Property="BorderThickness" Value="1"/&gt;
      &lt;Setter Property="Padding" Value="2"/&gt;
      &lt;Setter Property="Margin" Value="1" /&gt;
      &lt;Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" /&gt;
      &lt;Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" /&gt;
      &lt;Setter Property="Foreground" Value="{DynamicResource ControlForegroundBrush}" /&gt;
  
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="TextBox"&gt;
                  &lt;Grid x:Name="RootElement"&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 Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" To="{DynamicResource MouseOverBorderColor}" Duration="0:0:0.3"/&gt;
                                      &lt;ColorAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="{DynamicResource MouseOverControlBackgroundColor}" Duration="0:0:0.3"/&gt;
                                      &lt;ColorAnimation Storyboard.TargetName="PART_ContentHost" Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)" To="{DynamicResource MouseOverControlForegroundColor}" Duration="0:0:0.3"/&gt;
                                  &lt;/Storyboard&gt;
                              &lt;/VisualState&gt;
                          &lt;/VisualStateGroup&gt;
                      &lt;/VisualStateManager.VisualStateGroups&gt;
                      &lt;Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1" Opacity="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"&gt;
                          &lt;Grid x:Name="ContentGrid"&gt;
                              &lt;Border x:Name="MouseOverBorder" BorderThickness="1" BorderBrush="Transparent" Background="Transparent"&gt;
                                  &lt;ScrollViewer x:Name="PART_ContentHost" Padding="{TemplateBinding Padding}" Foreground="{TemplateBinding Foreground}" BorderThickness="0" IsTabStop="False"/&gt;
                              &lt;/Border&gt;
                          &lt;/Grid&gt;
                      &lt;/Border&gt;
                  &lt;/Grid&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>It is very odd to me that the background and boarder brushes, which are created and animated in exactly the same way, work perfectly regardless of whether I use Static or Dynamic resources, but that the Foreground color does not.</p>
  
  <p>If anyone has any ideas, or if there is a better way to do this, I'd love to hear it.</p>
  
  <p>David Mullin
  IMA Technologies</p>